Change required field message

0

How do I change the message below and stay with the simplicity and coherence I need?

Ihavethefollowingcode:

$(function() {
		var requiredCheckboxes = $('.periodicidade :checkbox[required]');
		requiredCheckboxes.change(function() {
			if (requiredCheckboxes.is(':checked')) {
				requiredCheckboxes.removeAttr('required');
			}
			else {
				requiredCheckboxes.attr('required', 'required');
			}
		});
});
<div class="periodicidade">
<input type="checkbox" required value=1>Segunda-feira
<input type="checkbox" required value=2>Terça-feira
<input type="checkbox" required value=3>Quarta-feira
<input type="checkbox" required value=4>Quinta-feira
<input type="checkbox" required value=5>Sexta-feira
<input type="checkbox" required value=6>Sábado
<input type="checkbox" required value=7>Domingo
</div>

Comments:

  • Marking of at least 1 (one) checkbox
  • Use setCustomValidity to change the message
  • asked by anonymous 14.10.2016 / 23:12

    1 answer

    0

    Good evening, gentlemen,

      

    [SOLVED] Below is the solution available in another forum:

    var requiredCheckboxes = $('.periodicidade :checkbox[required]');
    
    requiredCheckboxes.get(0).setCustomValidity('Mark at least one checkbox');
    
    requiredCheckboxes.change(function() {
      if (requiredCheckboxes.is(':checked')) {
      requiredCheckboxes.get(0).setCustomValidity('');
        requiredCheckboxes.removeAttr('required');
      } else {
      requiredCheckboxes.get(0).setCustomValidity('Mark at least one checkbox');
        requiredCheckboxes.attr('required', 'required');
      }
    });
        
    17.10.2016 / 18:07