Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Approach 1

English

A sample use case presents such where we need to bypass form validation in the event of rejecting a request.

This is possible by adding an empty/dummy section in a form and changing the section's load data store to Bean Shell Form Data Store to store this script below.
This script will remove form validation if the user clicks on "Reject" form button provided by the Process Enhancement Plugin.

Note

This approach will require the Process Enhancement Plugin to work.


Code Block
languagejava
import org.joget.apps.app.service.AppUtil;
import org.joget.apps.form.service.FormUtil;
import org.joget.apps.form.model.Element;
import org.joget.apps.form.model.Form;
import org.joget.apps.form.model.FormData;
import org.joget.apps.form.model.FormRowSet;

public FormRowSet load(Element element, String primaryKey, FormData formData) {
	//Feel free to change this "if" statement to suit your needs
    if ("#requestParam.process_reject#".equalsIgnoreCase("Reject")) {
        Form form = FormUtil.findRootForm(element);
        removeValidator(form, formData);
    }

    return null;
}

public void removeValidator(Element e, FormData formData) {
    e.setValidator(null);

    Collection children = e.getChildren(formData);
    if (children != null) {
        for (Element child : children) {
            removeValidator(child, formData);
        }
    }
}

//call load method with injected variable
return load(element, primaryKey, formData);

Approach 2

Another use case is using a button that is inside the form to remove validation. Simply replace "disable_validation" with a select box form element ID and replace "Disable" with the option value that will disable validation.

...