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

Question

Question

Field regex validation does not trigger for read-only fields populated via lookups

asked on August 16, 2017

We have Field 1, which populates Field 2 via lookups.

Field 2 has a regex. If the value that is looked up does not match the regex, it should flag the field as invalid and prevent submission.

This works fine if the field is editable. However, when we change it to read-only, it breaks. No error is displayed and the form can be submitted. Backend validation catches it, but we don't want that. We want to prevent submission.

I tried to trigger the change event on the field manually when it is populated:

$("#Field2").on("change", function() {
  $(this).trigger("change");
});

This makes it so that the invalid input message is shown, but the form can still be submitted.

tl;dr: Read-only fields populated via lookups have their regex rules ignored. How do I make it work with zero custom JavaScript?

0 0

Answer

SELECTED ANSWER
replied on August 16, 2017 Show version history

Hi Ege,

There is no front end validation on read-only fields. Since read-only fields cannot be modified by submitter, most likely it does not help to block submitting if validation fails on those fields.

Like in your case, instead of validating lookup populated field, I feel it more reasonable to add validation/limitation on lookup match field. 

If you do need validation on read-only fields, you have to use custom script:

$('form.cf-form').parsley({excluded: Parsley.options.excluded + ', .lf-no-validate'});

 

1 0

Replies

replied on August 16, 2017

Thanks. There are many situations where validating a read-only field may be necessary.

For example, let's say there is a purchase order form with three fields: Project Name, Project Status (read-only) and Purchase Amount.

When the user enters the project name, project status populates. But there is a business rule that says users should not be able to submit purchase orders for inactive projects. Instead, the form should warn them and prevent submission, so they can pick another project.

That's why it would be very useful to have a field option that says "run validations on this field" or something that can be checked/unchecked if the form administrator marks the field as read-only.

I'll try the script you gave.

 

 

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

Sign in to reply to this post.