Conditional Client Side Form Validation

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
mishanian
User
Posts: 120

Conditional Client Side Form Validation

Post 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?


arbei
User
Posts: 9284

Post by arbei »

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


mishanian
User
Posts: 120

Post 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?


arbei
User
Posts: 9284

Post by arbei »

arbei wrote:

You may ... use client side Form_CustomValidate instead.

You may use addCustomError(), see the example.


mishanian
User
Posts: 120

Post 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');


arbei
User
Posts: 9284

Post by arbei »

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


mishanian
User
Posts: 120

Post by mishanian »

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


arbei
User
Posts: 9284

Post by arbei »

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


Post Reply