I'm working with the jqueryui datepicker on this page - http://jqueryui.com/demos/datepicker/
How do I call it on a label instead of an input field? Is this possible?
$(". trigger"). click(function(){ $("#date"). datepicker("show"); });
By default, for <input> elements, the datepicker calendar opens in a small overlay when the associated text field gains focus. For an inline calendar, simply attach the datepicker to a <div>, or <span> element.
If you like to restrict access of users to select a date within a range then there is minDate and maxDate options are available in jQuery UI. Using this you can set the date range of the Datepicker. After defining these options the other days will be disabled which are not in a defined range.
I haven't looked at the code but I suspect that it assumes that it's attached to a <input type="text">
element.
So assume that you must have that element.
You can hide the <input>
and interact with the datepicker via calls to its methods from your label events.
$(labelselector).click(function() {
$(inputselector).datepicker('show');
});
re: The positioning problem
The above suggestions didn't work for me to get a clean ui. I have my datepicker control activated when people click a label, and I didn't want the textbox shown at all (the above css attempt was close, but still the textbox got focus amongst other issues).
The solution for me was to make the textbox that the datepicker is attached to a < input type="hidden" .... /> This solved all the issues for me (I put the hidden input control just prior to the label so that the offset from the input control was right for my label).
Notably, setting a normal input controls style to display: none, or visibility: hidden, etc. did not work.
The reason this solution worked is due to the clauses in the source of the datepicker control that only perform certain functions if "type != "hidden".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With