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

Question

Question

force form to evaluate required field conditions

asked on March 27, 2017

Hi - I have a form (v10.2) where the "Required" property of several fields changes based on the value of a drop-down field.  I have the javascript working fine to add/remove the "Required" status on the input of the fields, as well as the asterisk in the label <span> element of the fields.  The problem comes in forcing the form to evaluate whether or not a field should be required, and clearing the "red" input box and "Value is required" message.

Specifically, let's say that field "A" is required.  If it has no value in the input box, Forms turns the box red and displays "Value is required" below the box, once I blur out of the field input.  Now, if an event is triggered that removes the required condition on field "A", the asterisk goes away and I *could* Submit the form; however, the red box and "Value is required" stays until Submit is clicked - can be confusing for the user, and I would like to tidy it up.

I have tried adding "$('.fieldA input').change();" and "$('.fieldA input').trigger('change');" statements, but no luck.  Any suggestions?

Thanks, .... Steven.

 

1 0

Replies

replied on March 28, 2017

You can add following scripts to your previous script:

$('.fieldA input').removeClass('parsley-error');
$('.fieldA input').siblings('.parsley-errors-list').remove();

 

1 2
replied on March 27, 2017 Show version history

I think someone did something similar by adding this when the remove required triggers.

 

$('.req span.cf-required').remove();
$('.req input').removeClass('required').removeAttr('required');

A full example is here: https://answers.laserfiche.com/questions/56221/dynamically-change-required-fields

0 0
replied on March 27, 2017

Hi Raul,

Thanks for the reply.  That is a good example of javascript that removes the "required" attribute on the input, and asterisk on the label.  However, it does not force the form to re-evaluate the condition on that field.  So, if the box was already red (indicating that it needs to be filled in), it would stay red even though the required condition was removed.

 

1 0
replied on February 21, 2018

did you ever figure out a fix for this?

0 0
replied on February 14, 2018

Was this issue ever resolved?

0 0
replied on October 15, 2020

Hey folks, I found the solution.

$(the element you want to validate).parsley().validate()

You probably noticed all those 'parsley' things. Well, those are part of a JS library that LF Forms uses to do their validation. The above code snippet is how you can trigger the validation function on a particular element.

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

Sign in to reply to this post.