Hi
SugarCRM has lots of Javascripts functions to check a form in include/javascript/sugar_3.js. You can register as many fields as you like beforehand, with some conditions, and the check_form() functions validate them later.
For example, the following HTML script (triggered by Save button) registers certain fields by calling a custom function add_check(). The check_form() then validate them.
PHP Code:
<input title="{APP.LBL_SAVE_BUTTON_TITLE}" accessKey="{APP.LBL_SAVE_BUTTON_KEY}" class="button" onclick="this.form.action.value='Save'; return (add_checks(document.EditView) && check_form('EditView'));" type="submit" name="button" value=" {APP.LBL_SAVE_BUTTON_LABEL} " >
In add_check(), you can add a policy and register some fields to validate by calling addToValidate() as follows.
PHP Code:
function add_checks(f) {
if (f.name.value != "") {
addToValidate('EditView', 'date_start', 'date', 'true', '{$mod_strings['LBL_DATE_TIME']}');
addToValidate('EditView', 'duration_hours', 'int', 'true', '{$mod_strings['LBL_MAIL_SMTPPORT']}');
}
return true;
}
In this policy, if a user input something in the 'name' field, two additional fields - 'date_start' and 'duration_hours' - can not be blank.
Bookmarks