Invision Community 4: SEO, prepare for v5 and dormant account notifications By Matt Monday at 02:04 PM
IPCommerceFan Posted January 29, 2015 Posted January 29, 2015 (edited) Hi guys,I've finally had a chance to poke around 4.0 (Beta 6), and was wondering about the possibility of adding Custom Input Validation to custom fields in Commerce (specifically regex), similar to how it is available in custom fields for Pages?e.g. - When creating a new custom field, select Text as the field type, and a new option for Custom Input Validation appears where you can enter the validation criteria.It seems to me there should actually be parity across Commerce and Pages custom field type options, at least as far as things like this, field length, and text formatting are concerned. I would love to have a custom commerce field automatically converted to upper case once submitted, as well as limited to a certain number of characters and the option of setting a default value!Thanks! Edited January 29, 2015 by Steven@wt Ay hazea 1
IPCommerceFan Posted April 13, 2015 Author Posted April 13, 2015 It looks like this was added to custom fields for support requests (or it was already there?), but this would still be an awesome addition to custom package fields!P.S. - So far so good testing 4.0.0 with a copy of my live site. I *almost* switched to cs-cart because of missing features like this one, but the complete integration IPS offers is very hard to beat, even in this very early stage.
IPCommerceFan Posted January 21, 2019 Author Posted January 21, 2019 This is still not available as of 4.3.6: Commerce --> Store --> Custom Fields This is what is needed (specifically Default Value, Max Length, Custom Input Validation, and Apply text formatter): Pages --> Content --> Fields Fingers crossed for 4.4.
IPCommerceFan Posted March 5, 2019 Author Posted March 5, 2019 (edited) I got this working by modifying \IPS\nexus\Package\CustomField (the actual php file that relates to that class)! All I had to do was: - borrow the $form->add statements for pf_max_input and pf_input_format from \IPS\CustomField\CustomField - comment out the "unset" statements for those fields - Add the fields to the nexus_package_fields table in the database It works like a charm! Now to figure out how to do what I did in the form of a plugin or application since I don't really feel comfortable with the fact I edited the source files directly... Still hoping IPS will roll this into the core product, but I'm very thankful for the fact the framework was intuitive enough to allow this workaround! Edited March 5, 2019 by IPCommerceFan
Aaron M Posted September 3, 2019 Posted September 3, 2019 (edited) Highlighting this as a pressing issue for us still too. Surprised to see someone else encountering the same difficulties as we, but at least this shows there is a demand for this change. Edited September 3, 2019 by Aaron M Andrey777 and IPCommerceFan 2
IPCommerceFan Posted October 4, 2019 Author Posted October 4, 2019 With InvisionCommunity 4.x.x maturing and talks of 5.x.x starting to come up, I'm starting to wonder whether Commerce will survive considering a "simple" feature like this hasn't been given any attention since 2015. It would go a long way for me, and my business, if topics like this could at least be given some token acknowledgement. I understand having limited engineering resources since I deal with this every day as well. Having to triage what gets attention and what doesn't, inadvertently sending the wrong message, etc. It would just be nice to get a "Thanks for the suggestion", or "we're considering it", or even a "no", so that we can stop wondering if posting feature requests are a worthwhile use of time, and perhaps consider other options.
bfarber Posted October 4, 2019 Posted October 4, 2019 Setting aside the fact that only 2 people have responded to this topic (one of which was you, the original poster) - improvements and consolidation of code/consistency for custom fields features is something that has been discussed internally, more than once, but there is no current timeframe we can say to expect to see it. Unfortunately, it's simply not feasible to respond to every single topic to say "we've read this but there's nothing to note or add at this time". IPCommerceFan and DawPi 2
IPCommerceFan Posted June 4, 2020 Author Posted June 4, 2020 (edited) I needed this to be more robust, so I started poking around and discovered I could hook into \IPS\Helpers\Form\Text --> validate() and use custom php to do any kind of validation I want on a given custom commerce field! (custom Text field anyway, I haven't explored other types) In case anyone is need of this and finds this thread during their search, this is where you can run custom validation: //<?php /* To prevent PHP errors (extending class does not exist) revealing path */ if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) ) { exit; } class hook491 extends _HOOK_CLASS_ { /** * Validate * * @throws \InvalidArgumentException * @throws \DomainException * @return TRUE */ public function validate() { $dataToBeValidated = $this->value; //$this->value is anything that is entered into any field on the order form. /* * Run any if statement on your data to determine whether it should return false, some specific value, etc */ if ($dataToBeValidated > 0) { $validation == 1; } //"$this" doesn't know the id of the field, but it knows the name. Here we will evaluate the value entered for the Nexus package custom field with an ID of 5. ( nexus_packages_fields.cf_id in the database ) if ( $this->name == 'nexus_pfield_5' and $validation == 1 and !preg_match('/[A-Z0-9]+/i', $dataToBeValidated) ) //we can add any number of conditions to decide whether the field should be validated or not { throw new \InvalidArgumentException( 'form_bad_value_nexus_pfield_5' ); //added langauge bit to dev\lang.php "'form_bad_value_nexus_pfield_5' => 'Custom validation failure message'" } return parent::validate(); } } Hope this helps someone, and if there is a better way, I'm open to suggestions! Edited June 4, 2020 by IPCommerceFan Aaron M 1
Recommended Posts