I looked through the source code in workflow/public_html/lib/pmdynaform/build/js/PMDynaform.js:5962 and found the
form.isValid() function.
It will validate all the field in the Dynaform. You can call it like this:
getFormById("
form-id").isValid()
It returns
true if all fields are good and
false if any are required fields which are blank or any fields that don't match their validate regular expressions. It also shows red error messages under the fields that aren't validated in the Dynaform.
For example:
Code: Select allvar formId = $("form").prop("id");
if (getFormById(formId)isValid == true) {
$("#"+formId).saveForm();
}
If you want to validate a particular field you can call:
getFieldById("
field-id").validate()
It shows the red error message for an empty required field or a text field which doesn't match its validate regular expression. Otherwise is shows nothing in the Dynaform. The function returns the field's model object, which can be examined.
If you want to remove or add the red asterisk (*) next to fields to show that they are required, then use the following methods:
getFieldById("
field-id").showRequired()
getFieldById("
field-id").hideRequired()
These methods can only be used on fields that are marked as "required" or have a defined "validate" property. Unless you have a good reason to hide the asterisk, it is recommended to use the enableValidation() and disableValidation() instead of these methods.
If you need a array of all the fields in a Dynaform, you can use:
getFormById("
form-id").items.asArray();
For example:
Code: Select allvar aFields = getFormById( $("form").prop("id") ).items.asArray();
for (var i = 0; i < aFields.length; i++ ) {
aFields[i].validate();
}