How to apply onSubmit Client Script functionality for Cancel button

Community Alums
Not applicable

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. 

4 REPLIES 4

Anshul Shrivast
Tera Contributor

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

 

 

yuvarajkate
Giga Guru

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
}

 

 

yuvarajkate
Giga Guru

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
}