I’m trying to detect if any elements within a form have a data attribute called data-val.
If they do then run the function enclosed in the if statement. I’ve tried this:
var checkValidation = $('.uiModalContent').closest('form').find('input[data-val="true"], textarea[data-val="true"]');
if(checkValidation.length > 0) {
$.validator.unobtrusive.parseDynamicContent('.uiModalContent');
}
However it does not work as expected probably because the checkValidation becomes an array and checking using length is also probably not the best way of doing this.
Can anyone offer fixes / alternate solutions?
Thanks
Use the has attribute selector
I.E.:
Using
[data-val="true"]would mean that the value of[data-val]is"true", such as: