I’m using jQuery UI datepicker – the range version. I have a form and in the input field (text) of the “from date” I call the datepicker. It works fine.
The problem is that I also have in that field an image (of a calendar) that I set it’s class to be the same one as the field’s. BUT, while the field open the datepicker without problems, clicking the image seems do do nothing.
I know there are some questions regarding this issue, but nothing helps 😉
<input type="text" id="fromDate" value="Enter date" name="fromDate" class="fromDatePicker"/>
<img class="fromDatePicker" src="images/calender_icon_a1.jpg" id="ci1"/>
The js code:
$(function() {
$( ".fromDatePicker" ).datepicker({
defaultDate: "+1w",
dateFormat: 'dd/mm/yy',
altFormat: 'yymmdd',
altField: "#fromDateFormatted",
numberOfMonths: 2,
onSelect: function( selectedDate ) {
$('#toDate').datepicker( "option", "minDate", selectedDate );
}
});
Apparently you can’t bind a datepicker to an image. If we look at the datepicker source, we see this:
and
inlineis true if and only ifnodeNameisdivorspan. So when you try to bind the datepicker to an<img>, you get ignored without so much as a warning in the console.If you look at the Icon Trigger example on the jQuery-UI demos page, you’ll see the approved way of activating the datepicker using an icon:
and then remove your
img.fromDatePickerelement entirely.