Questions and discussion about using ProcessMaker: user interface, running cases & functionality

Moderator: amosbatto

By allanrp1
#814066
Hi.
I'm looking for a way to validate a form in javascript, and check if it's filled.
I saw there was a method in 2.8 "validateForm", but i don't see it in 3.2

How can i get that?
User avatar
By amosbatto
#814067
There is a "required" property for most types of fields and there is a "validate" property in text fields where you can enter regular expressions to validate the input. See:
http://wiki.processmaker.com/3.2/DynaFo ... s#Required
http://wiki.processmaker.com/3.0/Text_a ... s#Validate

I don't know of anyway to validate all the fields at once with JavaScript, except call grid.saveForm() or grid.submitForm().
By allanrp1
#814068
So it's not possible...
What can i do? i want to execute a script after a web entry, is there some way to automatically pass to another task without a user review?
User avatar
By amosbatto
#814069
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 all
var 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 all
var aFields = getFormById( $("form").prop("id") ).items.asArray();
for (var i = 0; i < aFields.length; i++ ) {
   aFields[i].validate();
}
User avatar
By amosbatto
#814070
allanrp1 wrote:So it's not possible...
What can i do? i want to execute a script after a web entry, is there some way to automatically pass to another task without a user review?
When the user clicks on a submit button, it should automatically do the validation and won't allow the user to submit without all the fields passing validation. If you don't want validation of the fields, then disable the fields that require validation with disableValidation() or create a separate form for web entry which doesn't have fields that require validation.

Hello Amos, Thank you for your advice. After this[…]

Hi. After updating processmaker from 3.1.3 to 3.2[…]

SMS Gateway

We Provide the Best SMS gateway to the USA . We a[…]

Because the code you shared displays documents fro[…]