0

Here is the jquery unobtrusive adapter which i am using for client side validation in the mvc application. Right now the validation is working but it is doing on onkeupevent . I am looking to have the clientside validation fireup only after the user leaves the field - Could anyone guide me on how to get this working?. I want to set this configuration only for certain fields not the entire form.

jQuery.validator.unobtrusive.adapters.add("compareemail", ["otherproperty"], function (options) {
    options.rules["compareemail"] = options.params.otherproperty;
    options.messages["compareemail"] = options.message;
});

jQuery.validator.addMethod("compareemail", function (value, element, params) {

    var reasonElement = $('#personalDetailsEmail');
    var testval = reasonElement.val();
    if (value != testval) {
         return false;
    }
    return true;
});

Thankyou

user845405
  • 1,461
  • 5
  • 23
  • 43
  • possible duplicate of [ASP.net MVC 3 jQuery Validation; Disable Unobtrusive OnKeyUp?](http://stackoverflow.com/questions/8022695/asp-net-mvc-3-jquery-validation-disable-unobtrusive-onkeyup) – artm Oct 29 '14 at 12:47

2 Answers2

0

If I understand correctly, this is what you need:

$('.parentOfFields').on( "blur", '.fieldsThatYouNeedAndHaveThisClass', function(){
    console.log($(this))
    //do stuff with $(this)
} )

careful: make sure .parentOfFields exists before this js code is executed, however the same does not apply to .fieldsThatYouNeedAndHaveThisClass, they can be created/added on the fly

more on blur here: http://api.jquery.com/blur/
blur means unfocus

Andrei Cristian Prodan
  • 1,114
  • 4
  • 17
  • 34
0

You can override onblur function for that particular control

@Html.TextBoxFor(m => m.UserName, new { onblur = "return false;" })
Mox Shah
  • 2,967
  • 2
  • 26
  • 42