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

Discussion

Discussion

Forms - Read-Only is disabling regular expression for validation

posted on November 14, 2022

Setting a field to read-only disables any regular expression validation. This is not good behavior though, it allows a user to submit invalid data. We want regular expression validation even when a field is read-only.

Read-only means we do not want the person manually changing the field value and we are not expecting them to input anything into the field, it is done through other means (lookup, calc, etc).

For example, with this email verification field called Emails Match. It is a read-only calculation driven field, but it needs to be a value of Yes before the user can submit.

0 0
replied on November 15, 2022

Which version of Forms is this? With self-hosted and the classic form designer, a better approach might be to use a custom validator rather than a separate read-only field.

Below is the code I use for email address confirmation fields.

  // custom validator for email confirmation
  window.Parsley.addValidator('emailconfirmation', {
    validateString: function(value, requirement, field) {
      var email = $('.emailAddress input').val().toLowerCase();
      var confirm = $('.emailConfirm input').val().toLowerCase();
      
      return (email == confirm || email == '' || confirm == '');
    },
    messages: {
      en: 'Email addresses do not match.',
    }
  });
  
  // assign validator to email field
  $('.emailConfirm input').attr('data-parsley-emailconfirmation','');

 

1 0
replied on November 15, 2022

This is a helpful workaround for sure, thanks for posting, but I wish the simple regular expression validation feature would work and not disable itself. There is no reason for it disable itself without any indication, it really confuses everyone. We had a validation on the field, simply wanted it to be read-only and  there is no logical problem with this, now it is suddenly not working even though it shows the validation is there.

0 0
replied on November 15, 2022 Show version history

I agree that this kind of functionality can be useful, but I would say that this is the "standard" behavior I see with web form validation.

Try making "Emails Match" Required. If this is classic forms, it is using Parsley validation and the default behavior of parsley is to ignore read-only fields.

However, if you make the field required, that should take precedence and force it to validate even if it is read-only, without adding scripts.

Basically, this is just how most validation libraries behave, not just Parsley; if a field is read-only, then the user cannot make changes, leading to the default behavior assuming it is valid.

As a result, the only other way around it is to use scripts to modify the validation rules or add custom validators.

2 0
replied on November 15, 2022

Aha! Making it required re-enabled the validation. I can't see how all these options effect each other clearly here, really I think they should not. This is a way better workaround though! Thanks!

0 0
replied on November 14, 2022

How about putting a change handler on the primary email field.  In the change handler, change the confirm email field property readOnly to false, then trigger a change event on the confirm email, and then change the readOnly property back to true.

0 0
replied on November 14, 2022

Do you mean in a custom script? I was just looking to train on the Regular Expression Validation feature that comes out of the box, but the fact that it does not work during read-only is not good. Shouldn't require a custom script workaround.

0 0
replied on November 14, 2022

Yeah, I was referring to JavaScript.  I don't know... it seems reasonable to not execute validation on read only fields.

0 0
replied on November 15, 2022

As the field is read-only, if the validation works, it will prevent the user from submit the form as the user cannot fix it since the value in the read-only field cannot be changed. 

0 0
replied on November 15, 2022

They can fix it by entering matching emails. If the field was read-only in such a way that it shouldn't validate, then I wouldn't have a validation on the field.

How then do I make sure the emails match?

0 0
replied on November 15, 2022

It sounds like you are wanting to use the feature to have end users fix issues from data coming from another system. For example, they type in their email address into a field, and it compares the value with another field that was populated from a database lookup. If the value being populated does not match the regular expression, you do not want it to be valid and prevent the submission? 

This goes with a question I asked back in 2015 about being able to mark a field as required and read-only at the same time. The idea in that post was that if the data was not correct, the end users would let the correct person know and they could clean the data at the source, thus helping keep the entire system clean over time.

I have had many examples like what I mention over my years working with Laserfiche where little features like this would be very helpful, but so far the only way around them is custom JavaScript.

0 0
replied on November 15, 2022 Show version history

You could also have that situation, but this is just asking the person to verify their email address and make sure there is no typos. There is simply 2 fields where they must type their email and a calculation to determine of one equals the other, which has a regular expression validation on it.

So without script, this customer got what they wanted, asking the user to enter their email twice, but they didn't get what they really wanted, preventing the user from entering 2 different email addresses.

 

Also, I don't have any issues combing read-only with required. They still can not submit the form if a read-only field is empty.

0 0
replied on November 15, 2022

I see what you're saying now. Sorry, a little slow this week.  What regular expression are you using?

0 0
replied on November 15, 2022

Just the literal "Yes"

We want the field to say Yes, that the emails match. The calculation is setting it to Yes or No depending on if the 2 fields above are equal

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

Sign in to reply to this post.