Is there any way to skip field validation when submitting the form?
In this form, If the user chooses 'Return' option in Action drop down list, no validation should be triggered for all fields in the form. I have successfully do this by i mplementing a customized Bean Shell Validator for all mandatory fields. It checks the value of Action field and if it is 'Return', no validation will be done. It works for fields located in the same form. However it is not working for some fields which are located in the subform. For these fields, the code that reads the value of Action field returns NULL (or maybe the field is not listed in FormUtil collection?).
Question, is there any way for the code to access forms/elements that are in the form that contains the subform where the fields is located?
Or
Question: Is there any other method to skip field validations upon form submission, based on certain condition?
----------
This is a snippet of my code:
--------------
public boolean validate(Element element, FormData formData, String[] values) {
boolean result = true;
Form form;
String sInitiator, sCurrentValue, sValue1, sValue2;
form = FormUtil.findRootForm(element);
//get field 1 value from form data object
String field1Id = "action_by_executor";
Element field1 = FormUtil.findElement(field1Id, form, formData);
if (field1 != null) {
//get value of field 1
String[] field1Values = FormUtil.getElementPropertyValues(field1, formData);
sValue1 = field1Values[0].trim();
}
sCurrentValue = values[0].trim(); // value of the current field
if (sValue1.indexOf("IsReturnedToInitiatorByExecutor") >= 0) {
result = true; //If this is a a pre-locked field, no need to check, as it is ready-only
} else {
result = true; //assume validation is okay
if (sCurrentValue.isEmpty()) { //just check, if it is empty return error
String id = FormUtil.getElementParameterName(element);
formData.addFormError(id, "Missing required value");
result = false;
}
}
return result;
}
//call validate method with injected variable
return validate(element, formData, values);
