mirror of
https://github.com/xdan/datetimepicker.git
synced 2024-11-18 06:24:22 +00:00
show parsed date/time to user after validation
https://github.com/xdan/datetimepicker/issues/425
This commit is contained in:
parent
ebbc1a1f39
commit
2266845f52
@ -575,7 +575,7 @@ var DateFormatter;
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
})();/**
|
})();/**
|
||||||
* @preserve jQuery DateTimePicker plugin v2.5.1
|
* @preserve jQuery DateTimePicker plugin v2.5.3
|
||||||
* @homepage http://xdsoft.net/jqplugins/datetimepicker/
|
* @homepage http://xdsoft.net/jqplugins/datetimepicker/
|
||||||
* @author Chupurnov Valeriy (<chupurnov@gmail.com>)
|
* @author Chupurnov Valeriy (<chupurnov@gmail.com>)
|
||||||
*/
|
*/
|
||||||
@ -1755,21 +1755,23 @@ var DateFormatter;
|
|||||||
if (options.allowBlank && (!$.trim($(this).val()).length || (typeof options.mask == "string" && $.trim($(this).val()) === options.mask.replace(/[0-9]/g, '_')))) {
|
if (options.allowBlank && (!$.trim($(this).val()).length || (typeof options.mask == "string" && $.trim($(this).val()) === options.mask.replace(/[0-9]/g, '_')))) {
|
||||||
$(this).val(null);
|
$(this).val(null);
|
||||||
datetimepicker.data('xdsoft_datetime').empty();
|
datetimepicker.data('xdsoft_datetime').empty();
|
||||||
} else if (!dateHelper.parseDate($(this).val(), options.format)) {
|
|
||||||
var splittedHours = +([$(this).val()[0], $(this).val()[1]].join('')),
|
|
||||||
splittedMinutes = +([$(this).val()[2], $(this).val()[3]].join(''));
|
|
||||||
|
|
||||||
// parse the numbers as 0312 => 03:12
|
|
||||||
if (!options.datepicker && options.timepicker && splittedHours >= 0 && splittedHours < 24 && splittedMinutes >= 0 && splittedMinutes < 60) {
|
|
||||||
$(this).val([splittedHours, splittedMinutes].map(function (item) {
|
|
||||||
return item > 9 ? item : '0' + item;
|
|
||||||
}).join(':'));
|
|
||||||
} else {
|
|
||||||
$(this).val(dateHelper.formatDate(_xdsoft_datetime.now(), options.format));
|
|
||||||
}
|
|
||||||
|
|
||||||
datetimepicker.data('xdsoft_datetime').setCurrentTime($(this).val());
|
|
||||||
} else {
|
} else {
|
||||||
|
var d = dateHelper.parseDate($(this).val(), options.format);
|
||||||
|
if (d) { // parseDate() may skip some invalid parts like date or time, so make it clear for user: show parsed date/time
|
||||||
|
$(this).val(dateHelper.formatDate(d, options.format));
|
||||||
|
} else {
|
||||||
|
var splittedHours = +([$(this).val()[0], $(this).val()[1]].join('')),
|
||||||
|
splittedMinutes = +([$(this).val()[2], $(this).val()[3]].join(''));
|
||||||
|
|
||||||
|
// parse the numbers as 0312 => 03:12
|
||||||
|
if (!options.datepicker && options.timepicker && splittedHours >= 0 && splittedHours < 24 && splittedMinutes >= 0 && splittedMinutes < 60) {
|
||||||
|
$(this).val([splittedHours, splittedMinutes].map(function (item) {
|
||||||
|
return item > 9 ? item : '0' + item;
|
||||||
|
}).join(':'));
|
||||||
|
} else {
|
||||||
|
$(this).val(dateHelper.formatDate(_xdsoft_datetime.now(), options.format));
|
||||||
|
}
|
||||||
|
}
|
||||||
datetimepicker.data('xdsoft_datetime').setCurrentTime($(this).val());
|
datetimepicker.data('xdsoft_datetime').setCurrentTime($(this).val());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
build/jquery.datetimepicker.full.min.js
vendored
4
build/jquery.datetimepicker.full.min.js
vendored
File diff suppressed because one or more lines are too long
2
build/jquery.datetimepicker.min.js
vendored
2
build/jquery.datetimepicker.min.js
vendored
File diff suppressed because one or more lines are too long
@ -1179,21 +1179,23 @@
|
|||||||
if (options.allowBlank && (!$.trim($(this).val()).length || (typeof options.mask == "string" && $.trim($(this).val()) === options.mask.replace(/[0-9]/g, '_')))) {
|
if (options.allowBlank && (!$.trim($(this).val()).length || (typeof options.mask == "string" && $.trim($(this).val()) === options.mask.replace(/[0-9]/g, '_')))) {
|
||||||
$(this).val(null);
|
$(this).val(null);
|
||||||
datetimepicker.data('xdsoft_datetime').empty();
|
datetimepicker.data('xdsoft_datetime').empty();
|
||||||
} else if (!dateHelper.parseDate($(this).val(), options.format)) {
|
|
||||||
var splittedHours = +([$(this).val()[0], $(this).val()[1]].join('')),
|
|
||||||
splittedMinutes = +([$(this).val()[2], $(this).val()[3]].join(''));
|
|
||||||
|
|
||||||
// parse the numbers as 0312 => 03:12
|
|
||||||
if (!options.datepicker && options.timepicker && splittedHours >= 0 && splittedHours < 24 && splittedMinutes >= 0 && splittedMinutes < 60) {
|
|
||||||
$(this).val([splittedHours, splittedMinutes].map(function (item) {
|
|
||||||
return item > 9 ? item : '0' + item;
|
|
||||||
}).join(':'));
|
|
||||||
} else {
|
|
||||||
$(this).val(dateHelper.formatDate(_xdsoft_datetime.now(), options.format));
|
|
||||||
}
|
|
||||||
|
|
||||||
datetimepicker.data('xdsoft_datetime').setCurrentTime($(this).val());
|
|
||||||
} else {
|
} else {
|
||||||
|
var d = dateHelper.parseDate($(this).val(), options.format);
|
||||||
|
if (d) { // parseDate() may skip some invalid parts like date or time, so make it clear for user: show parsed date/time
|
||||||
|
$(this).val(dateHelper.formatDate(d, options.format));
|
||||||
|
} else {
|
||||||
|
var splittedHours = +([$(this).val()[0], $(this).val()[1]].join('')),
|
||||||
|
splittedMinutes = +([$(this).val()[2], $(this).val()[3]].join(''));
|
||||||
|
|
||||||
|
// parse the numbers as 0312 => 03:12
|
||||||
|
if (!options.datepicker && options.timepicker && splittedHours >= 0 && splittedHours < 24 && splittedMinutes >= 0 && splittedMinutes < 60) {
|
||||||
|
$(this).val([splittedHours, splittedMinutes].map(function (item) {
|
||||||
|
return item > 9 ? item : '0' + item;
|
||||||
|
}).join(':'));
|
||||||
|
} else {
|
||||||
|
$(this).val(dateHelper.formatDate(_xdsoft_datetime.now(), options.format));
|
||||||
|
}
|
||||||
|
}
|
||||||
datetimepicker.data('xdsoft_datetime').setCurrentTime($(this).val());
|
datetimepicker.data('xdsoft_datetime').setCurrentTime($(this).val());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user