Is there anyway that i can remain focused on the input element after selecting a date in jQuery datepicker? Also is there anyway that i can prevent user from typing anything but enabling the tab key? I'm currently using prevent default method but i only need to enable the tab key. Thank you. Here is my current method.
$('body').on('focus',".dateSem",function() {
$(this)
.datepicker({
changeMonth: true,
changeYear: true,
changeDay: true,
showButtonPanel: true,
dateFormat: 'yy/MM/dd',
showMonthAfterYear: true,
monthNames: ["01", "02", "03", "04",
"05", "06", "07", "08", "09", "10",
"11", "12"
],
monthNamesShort: ["1", "2", "3", "4",
"5", "6", "7", "8", "9", "10",
"11", "12"
],
dayNamesMin: ["日", "月", "火", "水", "木",
"金", "土"
],
minDate: new Date,
currentText: '今日を選択',
closeText: '確定',
onClose: function(dateText, inst) {
$(this).datepicker(
'setDate',
new Date(inst.selectedYear,
inst.selectedMonth,
inst.selectedDay));
}
});
$(this).keydown(function(e) {
e.preventDefault();
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
I have made a simple implementation with the following html (please do not forget to include jquery and jqueryui)
And the javascript code
And the explanation
You select all input fields with class
.mydatepickerand assign an onkeydown event where you disable all key input except if the the keycode is equal to 9 (which mean equal to tab)Then you transform them also datepickers and inside the onSelect function (which runs after the user picks a date) and you call
$(this).focus()wherethisis the current input element