Is is possible to to have a depends on a jQuery remote validation?

Posted by David Kethel on Stack Overflow See other posts from Stack Overflow or by David Kethel
Published on 2012-02-14T05:26:23Z Indexed on 2012/09/12 3:38 UTC
Read the original article Hit count: 470

Filed under:
|

I am using jQuery remote validation to check if the description is already being used.

 Description: {
                    required: true,
                    maxlength: 20,
                    remote: function () {
                        var newDescription = $("#txtDescription").val();
                        var dataInput = { geoFenceDescription: newDescription };
                        var r = {
                            type: "POST",
                            url: "/ATOMWebService.svc/DoesGeoFenceDescriptionExist",
                            data: JSON.stringify(dataInput),
                            contentType: "application/json; charset=utf-8",
                            dataType: "json",
                            dataFilter: function (data) {
                                var x = (JSON.parse(data)).d;
                                return JSON.stringify(!x);
                            }
                        };
                        return r;
                    }
                },

The problem I have is that this remote validation occurs when the user has NOT modified the text box and comes back saying the description has been used because it found it self in the database.

So is it possible to only run the remote validation if the text field is different to what was originally in it?

I noticed the the jQuery required validation has a depends option, but I couldn't get it to work with the remote call.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about jquery-validate