“JQUERY Valider Submithandler” Réponses codées

JQUERY Validation Soumettre le gestionnaire

$("#myform").validate({
  submitHandler: function(form) {
    $(form).ajaxSubmit();
  }
});
Ahmed

JQUERY Valider Submithandler


function submithandler() {
	var errors = [];
	formFields.forEach( (field) => {
    	
        // loop to check all rules attached to the fields
        field.rules.forEach( (rule) => {
        
        	if (rule == 'required' && ! $(`#${field.id}`).val().length) {
            	errors.push(`${field.id} is required!`)
            } else if (rule.includes('max:')) {
            	let limit = rule.split(':')[1]; // this will get the number attached to the max rule
                if (limit > $(`#${field.id}`).val().length ) {
                	errors.push(`maximum length of charater must be `${limit})
                }
            }
        
        })
        
    })
    
    if (errors.length) {
      
     	return errors;
    }
  
  //do ajax post here
  
  
  
}


// edit the code below base on what u need

var formFields = [
	{
    	id:'name', // use to access the dom.eg $('#name')
        rules:['required']
    },
    {
    	id:'phone',
        rules:['required', 'max:11'],
    }
];
elezerk

Réponses similaires à “JQUERY Valider Submithandler”

Questions similaires à “JQUERY Valider Submithandler”

Plus de réponses similaires à “JQUERY Valider Submithandler” dans JavaScript

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code