jQuery remove validation rules by event

You could use the rules(‘remove’) method to remove your rules dynamically. Something like this on any event.

$('#fields').bind('change', function(){
	        val = this.checked;
	        if(val == true){
		    	//disable required fields
	        	$('#form_fields').rules('remove', 'required');
	        }
		});

Use rules(‘add’) method to add the rules back just before submit example:

$('#submit').click(function (e) {
    e.preventDefault();
    $('#form_fields').rules('add', 'required');
    $('#myform').submit();
});

By Keenlio, March 12, 2014

What do you think?

Leave a Reply

Your email address will not be published. Required fields are marked *


5 × five =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>