How do you stop catalog item from submitting until client script conditions are met

Khalnayak
Tera Guru

Hi Guys,

I have a email address field within a Catalog item.

I have created a an onChange catalog client script which checks if the email field is valid syntax and if not throws an error message at the top of the form.

Now that all works fine, but I want to either make the submit button greyed out / unavailable or the field to be kept mandatory until the client script conditions are met, 

Because as it stands, users can enter an invalid email address syntax and still submit it!

Below is my code:

find_real_file.png

 

Many thanks,

Usmaan.

1 ACCEPTED SOLUTION

Hi,

Try onSubmit client script.

and add return false; in if condition after error message.

Thanks,

Dhananjay.

View solution in original post

8 REPLIES 8

Jaspal Singh
Mega Patron
Mega Patron

Just after

g_form.addErrorMessage('...');

add 

return false;

Hi Jaspal,

Thank you. I added return false; as suggested above but it still allows the form to be submitted with invalid email address.

Hi,

Try onSubmit client script.

and add return false; in if condition after error message.

Thanks,

Dhananjay.

Hi,

please move the validation to onSubmit that is the only option

It is not recommended to grey out that submit button

inside the if(){

return false; // to stop form submission

}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader