Versions Compared

Key

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

...

Code Block
languagejava
import java.util.Arrays;
import org.joget.apps.app.service.AppUtil;
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.service.FormUtil;

public boolean validate(Element element, FormData formData, String[] values) {
    boolean result = true;

    //get field 1 value from form data object
    String field1Id = "field1";
    Form form = FormUtil.findRootForm(element);
    Element field1 = FormUtil.findElement(field1Id, form, formData);

    if (field1 != null) {
        //get value of field 1
        String[] compareValues = FormUtil.getElementPropertyValues(field1, formData);

        //compare the value of field 2 and field 1 are equals
        if (!Arrays.equals(values, compareValues)) {
            String id = FormUtil.getElementParameterName(element);
            formData.addFormError(id, "Value not equal!!!!");
            result = false;
        } 
    } else {
        //ignore if the field 1 not exist
    }

    return result; 
}

//call validate method with injected variable
return validate(element, formData, values);

Textfield / Textarea length not exceeding 500 characters

Code Block
languagejava
linenumberstrue
import java.util.Arrays;
import org.joget.apps.form.model.Element;
import org.joget.apps.form.model.FormData;
import org.joget.apps.form.service.FormUtil;
    
if(values[0].length() > 500){
    String id = FormUtil.getElementParameterName(element);
    formData.addFormError(id, "Value cannot be longer than 500 characters. You have entered " + values[0].length() + " characters.");
    return false;
}else{
    return true;
}


Use as Form Multi Row Load Binder

...