Update datepicker.js

This commit is contained in:
valhalla-creator 2025-05-13 21:26:34 +01:00 committed by GitHub
parent cef14f301f
commit 3cb4662363
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -83,7 +83,8 @@ export class DatePicker extends BlazeComponent {
{ {
'keyup .js-date-field'() { 'keyup .js-date-field'() {
// parse for localized date format in strict mode // parse for localized date format in strict mode
const dateMoment = moment(this.find('#date').value, 'L', true); const normalizedValue = Utils.normalizeDigits(this.find('#date').value);
const dateMoment = moment(normalizedValue, 'L', true);
if (dateMoment.isValid()) { if (dateMoment.isValid()) {
this.error.set(''); this.error.set('');
this.$('.js-datepicker').datepicker('update', dateMoment.toDate()); this.$('.js-datepicker').datepicker('update', dateMoment.toDate());
@ -91,8 +92,9 @@ export class DatePicker extends BlazeComponent {
}, },
'keyup .js-time-field'() { 'keyup .js-time-field'() {
// parse for localized time format in strict mode // parse for localized time format in strict mode
const normalizedValue = Utils.normalizeDigits(this.find('#time').value);
const dateMoment = moment( const dateMoment = moment(
this.find('#time').value, normalizedValue,
adjustedTimeFormat(), adjustedTimeFormat(),
true, true,
); );
@ -104,12 +106,14 @@ export class DatePicker extends BlazeComponent {
evt.preventDefault(); evt.preventDefault();
// if no time was given, init with 12:00 // if no time was given, init with 12:00
const timeValue = Utils.normalizeDigits(evt.target.time.value);
const time = const time =
evt.target.time.value || timeValue ||
moment(new Date().setHours(12, 0, 0)).format('LT'); moment(new Date().setHours(12, 0, 0)).format('LT');
const newTime = moment(time, adjustedTimeFormat(), true); const newTime = moment(time, adjustedTimeFormat(), true);
const newDate = moment(evt.target.date.value, 'L', true); const dateValue = Utils.normalizeDigits(evt.target.date.value);
const dateString = `${evt.target.date.value} ${time}`; const newDate = moment(dateValue, 'L', true);
const dateString = ${dateValue} ${time};
const newCompleteDate = moment( const newCompleteDate = moment(
dateString, dateString,
`L ${adjustedTimeFormat()}`, `L ${adjustedTimeFormat()}`,