Joget DX 8 Stable Released
The stable release for Joget DX 8 is now available, with a focus on UX and Governance.
...
Code Block | ||
---|---|---|
| ||
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); |
Another use case is using a button that is inside the form to remove validation. Simply replace "disable_validation" with the current button ID and replace "Disable" with the button value that will disable validation.
Code Block |
---|
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) {
//get disable_validation value from form data object
String disableValidatorID = "disable_validation";
Form form = FormUtil.findRootForm(element);
Element disableValidatorElement = FormUtil.findElement(disableValidatorID, form, formData);
if (disableValidatorElement != null) {
//get value of disable validator
String[] disableValidatorValues = FormUtil.getElementPropertyValues(disableValidatorElement, formData);
for(int i = 0 ; i < disableValidatorValues.length ; i++){
System.out.println("Toggle Button Value " + i + ": " + disableValidatorValues[i]);
//remove validator if checkbox value = Disable
if (disableValidatorValues[i].equalsIgnoreCase("Disable")) {
removeValidator(form, formData);
break;
}
}
}
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); |
Add Save as Draft with Validation in Form
...