0

I have created three email textfield in joget. I want the emails to be unique for every email field.enter image description here

The screenshort is attached. I want to display error if the email id of either of them are same !!

How can i do that?

`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);`

I had written this code but wasn't successfully. I would really help me if you can help me with J query code / JS code. AS joget supports it

Punam
  • 11
  • 2

1 Answers1

0

You can use simple javascript code if you are using it in HTML page, suppose input tag for email id has id "email1, email2, email3". Then

function validate()
{
email1 = document.getElementById("email1").value;
email2 = document.getElementById("email2").value;
email3 = document.getElementById("email3").value;

if(email1 == email2 || email2==email3 || email3==email1)
  {
     //Do something here

  }
}

And then you can validate the email ids are same or not by calling validate function before submitting the function by adding event listener on Submit button.
Or if you want to check the value when user enters the email then you can add input event listeners on all email input tags.

document.getElementById("email1").addEventListener('input', validate);
document.getElementById("email2").addEventListener('input', validate);
document.getElementById("email3").addEventListener('input', validate);

Abhishek Pratap Singh
  • 613
  • 3
  • 11
  • 18