Dónde poner $ .validator.setDefaults ({onkeyup: false}) para deshabilitar MVC3 onKeyup para atributo remoto

I have seen many answers for how to disable the onKeyup setting that the MVC3 Remote Validator has. The responses I have seen is to enter this:

$.validator.setDefaults({ onkeyup: false });

However I am not certain where to put this. I have tried putting it in its own script block at the head of my layout view, I have tried putting it in the jquery.validate.js file of my MVC3 project. Neither seems to work. So where do I put this script within my project to make it work?

preguntado el 01 de febrero de 12 a las 22:02

1 Respuestas

You have to tell the code to execute after the DOM has been parsed. To do this, simply wrap the code in a $() function:

$(function() {
    $.validator.setDefaults({ onkeyup: false });

This will ensure that the page elements will load, and then the script will be executed, setting your defaults.

Respondido 14 Feb 12, 23:02

i have another script on onblur, the script does not get called at all after setting onkeyup false, any suggestion? - bjan

Are you using the validator's onblur method? Or are you using a separate jquery onblur event? - Eric Westbrook

i am using controls onblur event and firing a JS function on that event - bjan

you should us the jquery validator's "onfocusout". Instead of declaring a boolean onfocusout: true, create a function: onfocusout: function(element) {//your onblur code here }. You will probably want the function to return "false", but since the element is passed, it would be easy to use an if statement to see if it is the element you wanted to target. if this element, do that, then return false. I hope this helps - Eric Westbrook

Thanks Eric, I have written my own date validation function and provided to the jquery validator as jQuery.validator.methods["date"] - bjan

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.