I am trying to ensure that a date is selected using the built-in datepicker. The built-in datepicker provides a hidden input field, so this requires a tough requirement. To try to display the message, I moved my error messages using invalidHandler.
My code is:
<script type="text/javascript">
jQuery('#date').datepicker({
inline: true,
beforeShowDay: checkDayOfWeek,
onSelect: function(dateText, inst) { $("#ship_date").val(dateText); }
});
</script>
<div id="date" style="font-size: 75%;" class="required"></div>
<input type="hidden" name="ship_date" id="ship_date" class="required" />
Me moving error message:
jQuery("#custform").validate({
invalidHandler: function(e, validator) {
var errors = validator.numberOfInvalids();
if (errors) {
var message = errors == 1
? 'You missed 1 field. It has been highlighted below'
: 'You missed ' + errors + ' fields. They have been highlighted below';
$("div.error span").html(message);
$("div.error").show();
} else {
$("div.error").hide();
}
},
});
My goal: when someone submits a form without selecting a date, she is given a message to enter the date before submitting the form. If we can add a class to the div to select a date, all the better.
Thanks for reading
source
share