Page 1 of 1

Conditional Client Side Form Validation

Posted: Thu Dec 08, 2022 11:50 am
by mishanian

Hi,
is it possible that based on the value of one field, the conditions of field validators to be changed?

example:

FieldOnlyPass is Boolean checkbox
FieldA is Mandatory
FieldB should be an integer.

Now if the value of FieldOnlyPass is true (the user checked the checkbox),
the form will be saved without checking if FieldA is mandatory and FieldB is an integer
is there any way to do so?


Re: Conditional Client Side Form Validation

Posted: Thu Dec 08, 2022 12:06 pm
by arbei

You may disable default validation for FieldA and FieldB and use client side Form_CustomValidate instead.


Re: Conditional Client Side Form Validation

Posted: Thu Dec 08, 2022 12:14 pm
by mishanian

Thanks. I will do it.
is there any way to make the label of the field red colour and show the error underneath (normal behaviour of PHPMaker) by calling any internal PHPMaker function for the errors?


Re: Conditional Client Side Form Validation

Posted: Thu Dec 08, 2022 12:56 pm
by arbei

arbei wrote:

You may ... use client side Form_CustomValidate instead.

You may use addCustomError(), see the example.


Re: Conditional Client Side Form Validation

Posted: Fri Dec 09, 2022 10:50 am
by mishanian

Thanks. Your instruction was perfect and working.
For scrolling to the field, I added the following code. is there any internal PHPMaker function for it?

$('html, body').animate({scrollTop: $('#x_' + thisField).offset().top + 'px'}, 'fast');


Re: Conditional Client Side Form Validation

Posted: Fri Dec 09, 2022 11:27 am
by arbei

If you don't need animation, you may use scrollIntoView() directly.


Re: Conditional Client Side Form Validation

Posted: Fri Dec 09, 2022 1:11 pm
by mishanian

Do you mean something like that?
const row = this.value;
row[thisField].scrollIntoView();


Re: Conditional Client Side Form Validation

Posted: Sat Dec 10, 2022 9:25 am
by arbei

The scrollIntoView() is a method of the HTML element itself.