From 95c23da6e01c54749d0942c90ecde2354bd23a8b Mon Sep 17 00:00:00 2001 From: Deven Bansod Date: Thu, 27 Oct 2016 08:02:37 +0530 Subject: [PATCH] Close the UI for invalid 'time' values too Signed-off-by: Deven Bansod --- js/functions.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/js/functions.js b/js/functions.js index 9ea336e205..2a36d5e3b8 100644 --- a/js/functions.js +++ b/js/functions.js @@ -4948,10 +4948,18 @@ function PMA_ignorePhpErrors(clearPrevErrors){ * by the Datetimepicker plugin (but is accepted by MySQL) */ function toggleDatepickerIfInvalid($td, $input_field) { - var dtexp = new RegExp(['^([0-9]{4})', + // 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('')); - if ($td.attr('data-type') === 'date' && ! dtexp.test($input_field.val())) { + 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');