Developers may want to add a custom validation to their custom developed field.
This should be possible without hacking our validation.js script file that contains the validation form field handlers.
1. Adding a custom class name to a form field (input or select form fields) e.g. validate-myvalidatename
2. Goto component parameters (or in content type parameters if you want to have different validation per content type) and inside ITEM FORM Tab (in component parameters) or inside ITEM FORM Slider (in content type parameters) , find parameter for custom javascript and add:
jQuery(document).ready(function() {
document.formvalidator.setHandler('myvalidatename',
function (value) {
// do so tests
some_true_false_result = ...;
return some_true_false_result;
}
);
});
Or you can enter same code inside the OnDisplayField(...) function of your custom field by using this PHP code:
static $js_validation_added = false;
if ( !$js_validation_added ) {
$js = "
jQuery(document).ready(function() {
document.formvalidator.setHandler('myvalidatename',
function (value) {
// do so tests
some_true_false_result = ...;
return some_true_false_result;
}
);
});
";
JFactory::getDocument()->addScriptDeclaration($js);
$js_validation_added = true;
}