This just disables it for everything and not just the desired element.
When you use the onkeyup
option, your custom function is going to completely over-ride the plugin's default function. Since you have no else
statement, then nothing else will happen when the field is not a match for tx_username
... effectively disabling onkeyup
validation entirely.
onkeyup: function (element) {
if (element.id == 'tx_username') {
return false;
}
}
The solution is to incorporate the default onkeyup
code into yours...
onkeyup: function (element, event) {
var excludedKeys = [
16, 17, 18, 20, 35, 36, 37,
38, 39, 40, 45, 144, 225
];
if (element.id == 'tx_username') { // disable 'onkeyup' for this field
return false;
} else { // otherwise, use the default code
if (event.which === 9 && this.elementValue(element) === "" || $.inArray(event.keyCode, excludedKeys) !== -1) {
return;
} else if (element.name in this.submitted || element.name in this.invalid) {
this.element(element);
}
}
}
DEMO: http://jsfiddle.net/ff77xbvb/
NOTE: This later version of the onkeyup
function will ignore the following keys...
// Shift => 16
// Ctrl => 17
// Alt => 18
// Caps lock => 20
// End => 35
// Home => 36
// Left arrow => 37
// Up arrow => 38
// Right arrow => 39
// Down arrow => 40
// Insert => 45
// Num lock => 144
// AltGr key => 225