diff --git a/js/functions.js b/js/functions.js index 7285d2c054..2a36d5e3b8 100644 --- a/js/functions.js +++ b/js/functions.js @@ -188,9 +188,12 @@ function addDateTimePicker() { timeFormat: timeFormat }); - // Add a tip regarding entering MySQL allowed-values for TIME data-type + // Add a tip regarding entering MySQL allowed-values + // for TIME and DATE data-type if ($(this).hasClass('timefield')) { - PMA_tooltip($(this), 'input', PMA_messages.strMysqlAllowedValuesTip); + PMA_tooltip($(this), 'input', PMA_messages.strMysqlAllowedValuesTipTime); + } else if ($(this).hasClass('datefield')) { + PMA_tooltip($(this), 'input', PMA_messages.strMysqlAllowedValuesTipDate); } }); } @@ -4939,6 +4942,30 @@ function PMA_ignorePhpErrors(clearPrevErrors){ $pmaErrors.remove(); } +/** + * Toggle the Datetimepicker UI if the date value entered + * by the user in the 'text box' is not going to be accepted + * by the Datetimepicker plugin (but is accepted by MySQL) + */ +function toggleDatepickerIfInvalid($td, $input_field) { + // Regex allowed by the Datetimepicker UI + var dtexpDate = new RegExp(['^([0-9]{4})', + '-(((01|03|05|07|08|10|12)-((0[1-9])|([1-2][0-9])|(3[0-1])))|((02|04|06|09|11)', + '-((0[1-9])|([1-2][0-9])|30)))$'].join('')); + var dtexpTime = new RegExp(['^(([0-1][0-9])|(2[0-3]))', + ':((0[0-9])|([1-5][0-9]))', + ':((0[0-9])|([1-5][0-9]))(\.[0-9]{1,6}){0,1}$'].join('')); + + // If key-ed in Time or Date values are unsupported by the UI, close it + if ($td.attr('data-type') === 'date' && ! dtexpDate.test($input_field.val())) { + $input_field.datepicker('hide'); + } else if ($td.attr('data-type') === 'time' && ! dtexpTime.test($input_field.val())) { + $input_field.datepicker('hide'); + } else { + $input_field.datepicker('show'); + } +} + /** * Unbind all event handlers before tearing down a page */ diff --git a/js/makegrid.js b/js/makegrid.js index 10ad2049ae..37c43c513e 100644 --- a/js/makegrid.js +++ b/js/makegrid.js @@ -1051,7 +1051,21 @@ function PMA_makegrid(t, enableResize, enableReorder, enableVisib, enableGridEdi timeFormat: timeFormat }); + $input_field.on('keyup', function (e) { + if (e.which == 13) { + // post on pressing "Enter" + e.preventDefault(); + e.stopPropagation(); + g.saveOrPostEditedCell(); + } else if (e.which == 27) { + } else { + toggleDatepickerIfInvalid($td, $input_field); + } + }); + $input_field.datepicker("show"); + toggleDatepickerIfInvalid($td, $input_field); + // unbind the mousedown event to prevent the problem of // datepicker getting closed, needs to be checked for any // change in names when updating diff --git a/js/messages.php b/js/messages.php index ce8fac8297..5475bbdbc6 100644 --- a/js/messages.php +++ b/js/messages.php @@ -518,11 +518,17 @@ $js_messages['strCopyEncryptionKey'] = __('Do you want to copy encryption key?') $js_messages['strEncryptionKey'] = __('Encryption key'); /* For Tip to be shown on Time field */ -$js_messages['strMysqlAllowedValuesTip'] = __( +$js_messages['strMysqlAllowedValuesTipTime'] = __( 'MySQL accepts additional values not selectable by the slider;' . ' key in those values directly if desired' ); +/* For Tip to be shown on Date field */ +$js_messages['strMysqlAllowedValuesTipDate'] = __( + 'MySQL accepts additional values not selectable by the datepicker;' + . ' key in those values directly if desired' +); + /* For Lock symbol Tooltip */ $js_messages['strLockToolTip'] = __( 'Indicates that you have made changes to this page;' diff --git a/js/tbl_change.js b/js/tbl_change.js index 30e7964522..99914f52b3 100644 --- a/js/tbl_change.js +++ b/js/tbl_change.js @@ -100,7 +100,7 @@ function isDate(val, tmstmp) } val = arrayVal.join("-"); var pos = 2; - var dtexp = new RegExp(/^([0-9]{4})-(((01|03|05|07|08|10|12)-((0[1-9])|([1-2][0-9])|(3[0-1])))|((02|04|06|09|11)-((0[1-9])|([1-2][0-9])|30)))$/); + var dtexp = new RegExp(/^([0-9]{4})-(((01|03|05|07|08|10|12)-((0[0-9])|([1-2][0-9])|(3[0-1])))|((02|04|06|09|11)-((0[0-9])|([1-2][0-9])|30))|((00)-(00)))$/); if (val.length == 8) { pos = 0; }