views:

161

answers:

2

i use remote method of validator for checking if username exists in DB

my scenario:

  1. form with one field (username of course)
  2. i filled field
  3. it passes validation, but i don't sending form yet
  4. going to DB inserting username that i filled in form that i still don't sent yet
  5. returning to my form press on submit btn
  6. voila, it pass validation (here the issue if u don't understand yet)

of course i did validation on the server side too, but it will be great that validation for remote method will fire too when sending form

p.s. i'm using 1.5.5 version but see that this issue still exists

+2  A: 

If I'm reading this properly, jQuery is not at fault here.

If this isn't correct let me know. I am imagining a registration form.

I go to your form, enter a username. jQuery says the username is available using the remote validation technique.

Before I click submit, someone else submits the same form with the same username, and gets it.

I can still submit the form, even though I have an already taken username.

This is a classic scenario. A concurrency problem. The data is now stale that was pulled by jQuery validation during my registration. You need to adjust for this scenario in your remote page or make jquery validation run on form submit as well. You could just call validate() on your form in the submit method of your form.

Jab
u right about scenario, but if i will call valid() on submit it still pass validation
msony
sounds like your remote page has stale data. If it calls your remote page after a row is inserted, it should stop you. Check your logic on the remote page.
Jab
A: 

i tried this one:

$(this).validate({
    submitHandler: function(form){
     if(form.valid()){
      form.submit(); 
     }
    }
});

but it still pass validation

msony