I got a button and a hidden input.
I want the datepicker opens below the button I click it. And the selected date is inserted in the hidden input.
I don't want to create a new button (using datepicker options), and I don't wanna show the input.
<button type="button" class="btn" id="date_button">Select Date...</button>
<input type="hidden" name="date" id="date_field" />
<script>
$('#date_button').datepicker({
showOn: "button",
onSelect: function( dateText ) {
$('#date_field').val( dateText );
$('#date_button').text( dateText );
}
})
</script>
Any ideas?
I did this by doing a .show().focus().hide() - works perfectly though it's a bit unclean:
$(document).ready(function() {
$('input').datepicker();
$('#mybutton').click(function() {
$('input').show().focus().hide();
});
});
http://jsfiddle.net/JKLBn/
This is a little hacky, but it seems to work okay:
input
instead of the button.var $button = $("#date_button"),
left = $button.offset().left,
top = $button.offset().top + $button.height();
$('#date_field').datepicker({
onSelect: function(dateText) {
$('#date_field').val(dateText);
$button.text(dateText);
},
beforeShow: function (event, ui) {
setTimeout(function () {
ui.dpDiv.css({ left: left, top: top });
}, 5);
}
});
$button.on("click", function() {
$("#date_field").datepicker("show");
});
Example: http://jsfiddle.net/StUsH/
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