You are viewing limited content. For full access, please sign in.

Question

Question

Integrated custom field validation

asked on April 25, 2021

I have a need to have field validation on single line text fields that includes the following:

  • Regular expression for matching the format
  • Masks using the JavaScript library as described in the Laserfiche documentation
  • Custom validation like calculating the check digit on special identifiers using JavaScript functions in the form

I have all of these working successfully for two different identifiers.  However, there is a reasonable order for these and I would like the error messages to report in the same manner and consistently.

An invalid field format can be reported under the field with a standard message on format.

An invalid identifier needs a longer message: "Check your record to make sure you have entered the value correctly."  (The check digit failed validation.)

I am finding the execution of the check digit validation is running several times for a field when there are two fields next to each other on the form. How do I make sure that the check digit validation is run only after all other validation using the mask and length is satisfied?  (Lost focus is probably the right time to fire check digit validation.?)

All these fields are required fields.  How do I have this final test integrated into the standard validation for the field and show the check digit message and prevent form submission?

There are snippets of parts of this in other posts but no answers that addresses the stages of validation and the full integration of all these validations in the standard message and field validation state for form submissions.

There really should be an in-depth document on advanced form development that answers these questions with examples.

Help!

0 0

Replies

replied on April 26, 2021 Show version history

The following is an example of custom validation (this should usually be contained within your document ready event handler).

  // custom validator named however you prefer
  window.Parsley.addValidator('customvalidation', {
    validateString: function(value, requirement, field) {
      // do your validation work here and return the results as true/false (valid/invalid)
      var valid = (value != ''); //example only
      
      return valid;
    },
    messages: {
      en: 'Validation failed message.' //customize this message with whatever you want it to say
    }
  });
  
  // assign validator to field using custom classes set on the target fields
  // make sure the end of "data-parsley-" matches the name you set for your validator
  $('.customField :input').attr('data-parsley-customvalidation','');

Forms uses the Parsley validation library, and there is some very in-depth documentation with examples that you can find at the following link: Parsley - The ultimate documentation (parsleyjs.org)

 

I'm not sure about controlling the order in which these rules are evaluated, but adding a custom validator this way will at least make it behave the same as the built-in validation options.

The documentation mentions a "priority" setting for the validation, but I've never felt a need to investigate that because it has always worked in a way that makes sense.

I've used custom validation like this a LOT and I can't say I've ever noticed a problem with the order of evaluation (I think it's prioritized like required > range/format > custom).

0 0
replied on April 28, 2021

Thank you Jason, I successfully added custom validations for a postal code and social insurance number and it all worked nicely with added error messages for check digit failures from the custom validator.  The field mask and other standard field constraints all worked at the same time (in the right order);

Now when I try to add standard jquery masks to the postal code within a Laserfiche address field I have not been successful.

$(".pcode input").mask("L0L 0L0"); works for a single line text field of the pcode class, but.. 

$(".Postal input").mask("L0L 0L0");  does not work for the Postal Code component of a LF address structure.

It would be nice  to be able to turn on the standard validation within the compound field.

Any tips?

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.