0

I experience a very strange behavior with Remote Validation in asp.net mvc.

These are the steps to reproduce the behavior:

1.) Enter user name "1" in the database
2.) Enter user name "1" in the Create User dialog -> nothing happens, I expected an error message
3.) I remove the "1" in the text box.
4.) I enter "1" again in the text box. -> Again nothing happens.
5.) Then I click with the mouse somewhere on the dialog
6.) Suddenly the error message appears, that user name "1" already exists ?

Is this the way the remote validation is expected to work in asp.net mvc ?

Even worse is when I click the submit button then the Validate action AND Create action are fired both which causes total unexpected/uncontrollable results.

Pascal
  • 12,265
  • 25
  • 103
  • 195

2 Answers2

0

Well by the process u described there can be two things happening..

  1. the jQuery's text change event only fires when the respective input tag looses focus(by a tab press or by a mouse click)

  2. the remote validation takes time in sending AJAX request and then getting the response so you should make sure that maybe the remote validation request is being sent at the right time but the response you are getting coincidentally coincides with the mouse click.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Parv Sharma
  • 12,581
  • 4
  • 48
  • 80
  • I just tested again and yes when I click outside the textbox the focus ist lost and the remote validated started. – Pascal Apr 29 '12 at 19:29
  • so you know the error message only appears when you receive the response of the ajax request.. – Parv Sharma Apr 29 '12 at 19:30
  • but a text changed event has something to do with typing a char not loosing a focus. I just compare it how it works in WPF. There exist a property changed and lost focus event. JQuery sucks then?! Is there a workaround for this? – Pascal Apr 29 '12 at 20:46
0

Actually it can be solved by simple solution we can put validation inside keypress event for spesific input so it would be

$("input[type='text'"]).keypress(function() {
  $(this).valid();
});
Rivera
  • 69
  • 1
  • 2
  • 8