1

I am trying to validate a field "organization.mailDomain" with jquery form validation plugin. My rules for validation are

rules : {
        "organization.name" : {
            required : true
        },
        "organization.mailDomain" : {
            required : true,
            remote : {
                url : "/domain/check",
                type : "post",
                contentType : "application/json",
                data : {mailDomain : $("#mailDomain").val()}
            }
        }

what i want is to send data as mailDomain=gmail.com but my current code is sending data as organization.mailDomain=abc.com&mailDomain=gmail.com. I know if i change field name from (organization.mailDomain) to (mailDomain) it will work, but i need the field name as it is.

UPDATE : By default the value is "gmail.com" but when i change the value to "abc.com" the post data is organization.mailDomain=abc.com&mailDomain=gmail.com

UPDATE : i am getting following error on server side

Caused by: com.fasterxml.jackson.core.JsonParseException: Unexpected character ('o' (code 111)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')

can any one kindly help me?????

1 Answer 1

1

In order to pass dynamic data to the remote function, you can pass a function as the data value, which will return the desired value... this function will get evaluated whenever the validator is called

remote: {
    url: "/domain/check",
    type: "post",
    contentType: "application/json",
    data: {
        mailDomain: function () {
            return $("#mailDomain").val()
        }
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

thanks for reply, now i am getting the dynamic data, now the post data is still "organization.mailDomain=abc.com&mailDomain=abc.com", how can i post just "mailDomain=abc.com".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.