Reputation: 8892
I'm making a custom jQuery validation method:
jQuery.validator.addMethod("workaround", function(input, element) {
if (!($(/*asdf*/).hasClass("intra-field-label")))
{
return true;
}
}, "This is required");
input
is the 'name' of the element. I am trying to get the 'id' of the element, or if I can simply check for the presence of a class using only a 'name', then I want to do that.
Upvotes: 0
Views: 738
Reputation: 536
Box9 is correct, the first parameter is the value, the second is the element containing the value. As you know you can also get the value by element.value
$.validator.addMethod("ValidateAdUser", function (value, element)
{
}
Upvotes: 0
Reputation: 93684
Actually, I don't think the first argument, input
, is the name of the element. It should be the value the input currently holds, according to the example given in the documentation.
The second argument is the element that is being validated. Therefore you can simply check:
if ($(element).hasClass('intra-field-label'))
Upvotes: 1
Reputation: 72242
jQuery.validator.addMethod("workaround", function(input, element) {
if (!($("input[name=" + input + "]").hasClass("intra-field-label")))
{
return true;
}
}, "This is required");
Considering that your element will always be an <input />
.
Otherwise change to $("[name=" + input + "]")
Upvotes: 1