jQuery: The Write Less, Do More JavaScript Library

(validate) validation (plugin) remote message option problem.

View: New views
3 Messages — Rating Filter:   Alert me  

(validate) validation (plugin) remote message option problem.

by adwen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I have this horrible problem that i've spent like 2 days looking for a
easy solution but to no avail. I've been using the jQuery validation
plugin to do the validation for me and it has working great so far.
I've added the remote option and it communicates perfectly with the
server and sends the responde back to the user.

I don't know it is a bug or that is the way the author intended for it
to work but if there is a problem with the remote validation. I've
made an function that should be triggered and send a 'callout' to the
field. I add this function for the remote in the message section in
'rules'. This should ONLY happen when the field is validated as
false.

For some reason the second i press on submit it doesn't matter the
outcome of the remote validation. it simply executes my function at
all times.

My code:

 $(document).ready(function() {
         $("#form").validate({
             errorClass: "errorClass",
             ignoreTitle: true,
             errorPlacement: function(error, element) { },
             rules: {
                 Name: {
                     required: true,
                     minlength: 2,
                     remote: {
                         url: '<%= Url.Action("VerifyName")%>',
                         type: 'POST',
                         dataType: 'json',
                         data: {
                             Name: function() {
                                 return $('#Name').val();
                             },
                             Id: function() {
                                 return selectedID;
                             }
                         }
                     }
                 },
                 Category: {
                     required: true,
                     minlength: 1,
                     digits: true
                 },
                Country: { required: true }

             },
             messages: {
                 Name: {
                     required: "",
                     minlength: "",
                     remote:  function(element) {
                         //alert("hello")
                         showCallOut("Name", 'This name already
exists');
                     }
                 },
                 Category: ""
             },
             focusInvalid: false,
             onkeyup: false,
             onfocusout: false,
             highlight: function(element, errorClass) {
                 $(element).addClass(errorClass);

             },
             unhighlight: function(element, errorClass) {
                 $(element).removeClass(errorClass);

             }
         });

     });

What can i do to solve this issue?  Is this a bug in validation
plugin? How do I contact the owner of the validation plugin?
I've read a thread with the similar problem but the solution doesn't
work in my situation:

http://groups.google.com/group/jquery-en/browse_thread/thread/45ce7e9f59979b67/089e0b018e79da5a?#089e0b018e79da5a


Re: (validate) validation (plugin) remote message option problem.

by Nemezya :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I don't know if it can help but i had a quite similar problem.
The function associated to my remote test was triggered whatever the
server response because of a bad json encoding for the true/false
response.
I used json_encode() and it works now.




Re: (validate) validation (plugin) remote message option problem.

by adwen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

Thnx for the reply!

I'm programming in ASP.NET (mvc) so we do not have the 'json_encode()'
function. What we actually do have is this 'Json()' method to properly
format the response into JSON.  When I don't use a custom message (and
only use (un)highlight to color the textfield borders to Red) it works
GREAT! So I assume that it is getting the response (which is either
'true' or 'false') correctly. I don't know if validation plugin
(1.5.5) see a difference between a string or a boolean. Maybe it is
getting a string and it is expecting a boolean. I don't know what is
going wrong here and i do not know how to debug the validation plugin.

I find it weird too that I'm not getting any reaction from the plugin
creator(Jörn) or from someone else who is actively involved with the
development of this plugin.

But once more thnx for the reply! keep them coming! Any suggestion
that might help is appreciated! ;)