The build in remote attribute in asp.net mvc 3 does the validation "onchange".
I want it to validate on blur, is there a way to custom it? or there is something else for doing so? I'm sure it's a very common need.
Asked
Active
Viewed 1,950 times
2
bkaid
- 50,475
- 21
- 110
- 127
gdoron is supporting Monica
- 142,542
- 55
- 282
- 355
-
possible duplicate of [ASP.NET Remote Validation only on blur?](http://stackoverflow.com/questions/5407652/asp-net-remote-validation-only-on-blur) – Judah Gabriel Himango Nov 17 '11 at 23:29
2 Answers
7
You could set default values like this and disable validation when a key is pressed:
$.validator.setDefaults({ onkeyup: false });
Darin Dimitrov
- 994,864
- 265
- 3,241
- 2,902
-
Thanks for the answer, can you please explain me what that line of code does? I didn't see any explantion in the line you wrote. Thanks again! – gdoron is supporting Monica Aug 21 '11 at 18:03
-
1@gdoron, as the documentation explains, the `setDefaults` method allows you to override default configuration values for the jquery validate plugin. Setting `oneyup` to false indicates that validation should not be performed when the user releases a key. – Darin Dimitrov Aug 21 '11 at 20:28
-
Is there any different between the code you wrote and the code below written by offbysome? – gdoron is supporting Monica Aug 21 '11 at 21:23
-
1@gdoron, yes there is. When you use the `setDefaults` method you are explicitly setting default values for all validation plugins on the current page. With the code below you are attaching the `validate` plugin additionally and thus conflicting with the ASP.NET MVC 3 unobtrusive validator plugin. – Darin Dimitrov Aug 23 '11 at 15:29
-
In a different page I need to disable the onkeyup for only one property. How can I do that – gdoron is supporting Monica Nov 20 '11 at 07:57
3
Assuming you are using jQuery validation and not MS Ajax Validation in ASP.NET MVC 3, you would turn off onchange validation (technically its onKeyUp validation) by using this:
$(".selector").validate({
onkeyup: false
});
bkaid
- 50,475
- 21
- 110
- 127