Created
July 27, 2021 14:29
-
-
Save emulsion-io/303a98e59375af7f804c82b0a1e74664 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Permet de rendre une checkbox obligatoire parmis plusieurs | |
* | |
* Jquery required. | |
* | |
* <input name="tranche[]" type="checkbox" class="tel-checkbox" id="modal-usual-call-matin" value="matin" required> | |
* <input name="tranche[]" type="checkbox" class="tel-checkbox" id="modal-usual-call-midi" value="midi" required> | |
* <input name="tranche[]" type="checkbox" class="tel-checkbox" id="modal-usual-call-apmidi" value="apres-midi" required> | |
* <input name="tranche[]" type="checkbox" class="tel-checkbox" id="modal-usual-call-soir" value="soir" required> | |
* | |
*/ | |
var elementform = document.getElementsByClassName("tel-checkbox"); | |
var requiredCheckboxes = $('.tel-checkbox:checkbox[required]'); | |
requiredCheckboxes.change(function(){ | |
if(requiredCheckboxes.is(':checked')) { | |
for (var i = 0; i < elementf.length; i++) { | |
elementform[i].setCustomValidity(""); | |
} | |
requiredCheckboxes.removeAttr('required'); | |
} else { | |
requiredCheckboxes.attr('required', 'required'); | |
} | |
}); | |
document.addEventListener("DOMContentLoaded", function() { | |
for (var i = 0; i < elementform[1].length; i++) { | |
elementform[i].oninvalid = function(e) { | |
e.target.setCustomValidity(""); | |
if (!e.target.validity.valid) { | |
e.target.setCustomValidity(clinic_var_client.error_form_msg.checkbox); | |
} | |
}; | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment