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

Question

Question

Can a Formula be used to check line formatting in multiline field?

asked on October 14, 2022

In one of our Forms processes we have a multiline field where users paste text into it. The text usually has multiple lines, and each line needs to be in a specific format to be valid. Rather than have Workflow check it after the form is submitted, I am wondering if there might be a way for a formula to be able to check the formatting of each line that is entered?

0 0

Replies

replied on October 14, 2022

I suppose it would depend on the evaluation. The SPLIT function could be used to break the text up based on line breaks, but I don't know if that would really lead to anything useful for this.

Since multi line fields don't have regex, I'd say your best option is a custom validator.

   window.Parsley.addValidator('multilineformat', {
    validateString: function(value, requirement, field) {
      var valid = true; // default validation output
      
      // loop values split on line break
      // may need adjustment for other possibilities like carriage returns
      $.each(value.split('\n'),function(index, value){
        // add your evaluation here and return false if not valid
        if (value == 'test') {
          valid = false; // set validation to false if any line fails
        }
      });
      
      return valid;
    },
    messages: {
      en: 'Invalid format.', // whatever error message you want
    }
  });
  
  // assign validator to field
  $('.myMultiLine textarea').attr('data-parsley-multilineformat','');

 

0 0
replied on October 14, 2022

Thanks Jason. I'll take a look at your script.

0 0
replied on October 20, 2022

To evaluate the value based on a regular expression would one just put the expression in or is there something else that needs to be added for it to work correctly?

0 0
replied on October 20, 2022

You would add a regex comparison in and return false if it fails the check.

For example,

if (!string.match(regex)) return false;

or using a RegEx object

if (!regex.test(value)) return false;

Something along those lines. to replace if (value=='test')

 

0 0
replied on December 2, 2022 Show version history

I've been playing with this today and haven't been able to get it to work yet. In the Dev Tools Console it says "Uncaught SyntaxError: Invalid or unexpected token". The issue appears to be when I enter the regex.

0 0
replied on December 2, 2022 Show version history

What does your code look like with the regex? The specific code/syntax would depend on whether you're using .match() or .test()

0 0
replied on December 5, 2022

Well, I removed it at some point, so I don't have it anymore. As an example of what we're trying to do, we have a Forms process that has a multiline field. The end users are supposed to enter GL Codes on each line in a specific format (this is part of a larger process and there is a reason they enter it this way). The data is eventually applied to a repository entry's metadata. For this example, there is a constraint on the GL Entry field in the repository of \d+-[\dxX]+-\d+-\d+:\-?\d+\.?\d?\d?. Using what you posted, how would you add that so Forms could check each line adheres to that format for the specific field?

0 0
replied on January 13, 2023

Did you have any luck on this Jason?

0 0
replied on January 13, 2023

I haven't really messed with this too much, but the code should work. From the error message you described it sounded like it just needed a change in how the RegEx syntax was added to the code.

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

Sign in to reply to this post.