You're breaking the plugin, because you cannot put a conditional statement within an object literal...
rules: { // <- this is part of an object literal, NOT a function
domain: {
required: true
},
playerClass: {
required: true,
},
if (adTag.value !== '') { // <- no good! conditional is outside of a function
url: true
}
},
A conditional statement can only go inside of a function.
The rules option only takes a comma separated list of key:value pairs that represent the field name where the value is its rules. Then you can use a function to construct the parameter for the rule.
You could do something like this...
rules: {
domain: {
required: true
},
playerClass: {
required: true,
},
adTag: {
url: function() {
// conditional statement to return true or false
}
}
},
I need to be able to validate an input field ... only if the input is not blank.
Without using the required rule, that is already the default behavior!
rules: {
domain: {
required: true
},
playerClass: {
required: true,
},
adTag: {
url: true // only gets evaluated when the field is not empty
}
},
DEMO: http://jsfiddle.net/bk7x129p/1/
requiredrule, the other rules are automatically ignored when the field is left blank.