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) {
            },
        });
    }
});
Anjith K P
  • 2,158
  • 27
  • 35

1 Answers1

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;
    }
});
Arun P Johny
  • 384,651
  • 66
  • 527
  • 531
  • 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. – user2397380 May 28 '13 at 12:03
  • This solved the issue with response: http://stackoverflow.com/questions/11479383/jquery-validation-remote-method-wont-trigger-after-valid – user2397380 May 29 '13 at 08:25