Hi,
I need to remove or add validation dynamically to select2 element. For example, when the page loads, I may want the element to be required, or may not. I can control that easy enough. But then, based on another click, I need to manipulate that ‘requirement’ using javascript. I’ve tried multiple things I’ve seen online, but haven’t gotten a solution.
One thing I found was that I could include the ‘required’ attribute in the select element. I did that and it works correctly giving me a message when I don’t select at least one element. But then, I tried this code to ‘remove’ required attribute:
$('#disciplinesCoveredID').removeAttr('required');
I’ve also tried this as well:
$('#disciplinesCoveredID').select2().removeAttr('required');
I’m sure it’s something simple I’m doing wrong. I need to be able to remove it and also add it back. Any suggestions?
Thanks!
Dave