jeudi 4 juillet 2019

Return invalid submission if no Checkbox is checked on initial load of the page

I need my error handlers to fire if the form is submitted without any selection on initial load. If I add .prop('required') onready, it would include other checkboxes that has values loaded from our db. Which means my error handler would fire although there are already fields selected.

$form.on('submit', function(){
$(this).find('input[type=checkbox]').filter(':checked').length;
$('.cboxgrp').each(function(){
if(cboxgrp===0){
$(this).find('input[type=checkbox]').prop('require',true);}});

The result on the above code is 1 mouseclick(literally) more that what I expected to happen. This would set the checkboxes to required on the first click of the submit button, then on the second try is shows my error handlers.

Is there a way to achieve it.




Aucun commentaire:

Enregistrer un commentaire