How to apply onSubmit Client Script functionality for Cancel button

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2024 07:56 PM
I want to apply on submit client script for cancel button.
Scenario: if a user clicks the cancel button, do not let them submit the form if their email address is incorrect.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2024 07:59 PM
Hi @Community Alums ,
Please refer to the links which will help you :
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2024 08:28 PM
Hi @Community Alums
Get the email id of current user and the email id which needs to be validate.
Email id A = '';
Email id B = '';
Compare both email id.
If email id is not match then give alert and return false.
alert('Email id incorrect');
return false;
If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!
Regards,
Anshul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2024 10:53 PM
Hope you find this useful.
Explanation of the client script:
- g_form.getActionName(): Checks the action triggered by the button click.
- Regex Validation: Ensures the email matches a valid format.
- Error Message: Displays a user-friendly error if the validation fails.
- return false: Stops the form submission when the Cancel button is clicked with an invalid email.
function onSubmit() {
// Check if the Cancel button was clicked
if (g_form.getActionName() === 'cancel') {
var email = g_form.getValue('email'); // Replace 'email' with the correct field name
var emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(email)) {
g_form.addErrorMessage('Error Message.');
return false; // Prevent the form submission
}
}
return true; // Allow submission for other actions
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2024 10:54 PM
Hope you find this useful.
Explanation of the client script:
- g_form.getActionName(): Checks the action triggered by the button click.
- Regex Validation: Ensures the email matches a valid format.
- Error Message: Displays a user-friendly error if the validation fails.
- return false: Stops the form submission when the Cancel button is clicked with an invalid email.
function onSubmit() {
// Check if the Cancel button was clicked
if (g_form.getActionName() === 'cancel') {
var email = g_form.getValue('email'); // Replace 'email' with the correct field name
var emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(email)) {
g_form.addErrorMessage('Error Message.');
return false; // Prevent the form submission
}
}
return true; // Allow submission for other actions
}