0

I am trying to validate a select box using a remote resource when the select box is changed but the remote resource is not getting triggered:

Here is the code:

$("#register_student_2").validate({
    submitHandler: function(form) {
        $(form).ajaxSubmit({
            rules: {
                relationship: {
                    required: true,
                    remote: function() {
                        return {
                            type: "POST",
                            url: "includes/check-relationship.php",
                        }
                    }
                },
            },
            beforeSubmit: function() {
                //do something
            },
            clearForm: true,
            success: function(data) {
            },
        });
    }
});

1 Answer 1

1

The rules must be passed to the validate option, not to the ajaxSubmit options

$("#register_student_2").validate({
    rules: {
        relationship: {
            required: true,
            remote: function () {
                return {
                    type: "POST",
                    url: "includes/check-relationship.php",
                }
            }
        },
    },
    submitHandler: function (form) {
        $(form).ajaxSubmit({
            beforeSubmit: function () {
                //do something
            },
            clearForm: true,
            success: function (data) {},
        });
        return false;
    }
});
Sign up to request clarification or add additional context in comments.

2 Comments

I have tried this and I am now getting the remote resource been called, I seem to not be able to get the correct response that is accepted: The documentation says this: The response is evaluated as JSON and must be true for valid elements, and can be any false, undefined or null for invalid elements, using the default message; or a string, eg. "That name is already taken, try peter123 instead" to display as the error message. . I have tried returning many different message types such as a string, an empty string but this select element is preventing the form submitting.
This solved the issue with response: stackoverflow.com/questions/11479383/…

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.