javascript - Accessing current context within JQuery validator -
i have custom jquery validator validates if email entered exists in list. displaying 3 input fields using foreach in cshtml. have 1 input field in code. in "validator.addmethod", trying access text field using $(this). returning validator. here code:
$.validator.addmethod("emailtextfield", function (value, element) { var designeeid = $(this).attr("data-level"); var newemail = $("#txtupdate" + designeeid).val(); var exists = true; $("#emaillist" + designeeid + " > .list-group-item > .email").each(function () { if ($(this).html().tolowercase() == newemail.tolowercase()) { exists = false; } }); return exists; }, "email exists in list."); });
i using 'data-level' access particular textfield first "this" in above code. returns validator. if give in class of textfield instead of "this", considering 3 textfields. need access textfield in current context.
if want access element being validated, should work:
var designeeid = $(element).attr("data-level");
Comments
Post a Comment