ADD Form Validation With Custom Message

It will be done by one step only! Lets do this,

1. Add a reference to the JavaScript file which will be needed for event binding.

Path: custom/modules/<desired_module>/metadata/editviewdefs.php

<?php

$viewdefs['<desired_module>']['EditView']['templateMeta']['includes'] =
    array (
        array (
        'file' => 'custom/modules/<desired_module>/js/editview.js',
        ),
    );
?>

2. Add the JavaScript file you want to include into the location you referenced above(custom/modules/<desired_module>/js/editview.js).

3. Write following code in editview.js file.

add_error_style('form name', 'field name', 'your message');

For Example :
add_error_style('EditView', 'replan_start_date', 'Replan Date should not be older than Booking Date');

4. Quick Repair, then hard refresh your browser. All Done !

5. Done! Refresh the page and start testing.

Note :

1. Read the comments in code carefully and replace the variables as asked.
2. Here, <desired_module> means the module name you see in the URL, for example, Contacts, Leads, Accounts, etc.
3. You may find the field names and its labels in Admin > Studio > <Your_module> > Fields > <Choose correct field> > Take 
Field Name and System Label.

Hope you find this blog post helpful.

Feel free to add comments and queries, that helps us to improve the quality of posts.

You can contact us at info@infotechbuddies.com

Thank you.

Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *