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

Question

Question

Any way to make Forms field rules case insensitive?

asked on December 27, 2023

I have some fields I need to compare and am running into issues with upper and lower case. Specifically, I want to compare a couple of email fields and put up a warning if they match (can't have users reviewing and approving their own requests). However, the fields evaluate as having acceptable, different values if the capitalization is different.

I have worked around it by forcing my view to be lowercase and then using JS to force the user input to lowercase, but now I have to add in more fields for other steps and it's getting more complicated. Is there a setting somewhere that can do the field evaluation in a case-insensitive way?

0 0

Replies

replied on December 27, 2023

I would create a third field that does a formula to identify if the two email addresses match when converted to lowercase.  This example checks the two fields and displays the word MATCH if they are matching or the words NO MATCH if they do not match. 

=IF(LOWER(email1)=LOWER(email2),"MATCH","NO MATCH")

You could hide this extra field using Field Rules or CSS, and then build the field rule that displays your warning when this field is NO MATCH.

Does something like that meet your needs?

0 0
replied on December 27, 2023

Thanks, Matthew. That would work if it was just a couple fields but it's getting more complicated. I have the requestor field and 2 approval manager selection fields. And then the approval can be picked up by a different manager so have to make sure that the actual manager isn't the same as the requestor and that the two approval managers are different.

0 0
replied on December 27, 2023

I think your situation is a good use case for built-in options to enable/disable case-sensitive comparison in field rules, however, at the moment I don't think there is a simple out-of-the-box solution.

Are you using the classic designer or the modern designer? If you're using the classic designer, you could use JavaScript to create custom validation rules.

The biggest downside to relying on normal field rules is that the warning alone would not prevent the user from ignoring it and submitting anyway.

If you are able to use custom validation rules in a classic form, you can leverage the built-in validation to both show the error message and prevent submission.

In the following example (classic designer), each field with the uniqueemail class will have the validator assigned to require uniqueness, which makes it pretty easy to scale because you only need to add the class to each field.

$(document).ready(function (){
  // custom validator for email addresses
  window.Parsley.addValidator('uniqueemail', {
    validateString: function(value, requirement, field) {
      // convert to lower case and set default result
      value = value.toLowerCase();
      var isValid = true;
      
      $('.uniqueemail input').each(function (){
        // check values for all other fields except self
        if(!$(this).is(field.$element) && $(this).val().toLowerCase() == value){
          isValid = false;
        }
      });
      
      return isValid;
    },
    messages: {
      en: 'Email address already used.',
    }
  });
  
  // assign validator to email field
  $('.uniqueemail input').attr('data-parsley-uniqueemail','');
});

There's a lot of different ways you could handle the actual comparison, but this is a quick example of how the custom validator approach could work.

A little more code would be needed if you're dealing with tables/collections and some of the email fields may be added after the form has already loaded.

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

Sign in to reply to this post.