3
0
Fork 0

Apply default time on manual entry of date string

16.0
Akim Juillerat 2024-08-13 17:38:08 +02:00
parent 3af6b1d7f4
commit bda8836396
1 changed files with 22 additions and 0 deletions

View File

@ -4,6 +4,7 @@
import {DateTimePicker} from "@web/core/datepicker/datepicker";
import {patch} from "@web/core/utils/patch";
import {localization} from "@web/core/l10n/localization";
patch(DateTimePicker.prototype, "DateTimePickerDefaultTime", {
onMounted() {
@ -21,6 +22,27 @@ patch(DateTimePicker.prototype, "DateTimePickerDefaultTime", {
}
});
},
isStrDate(input_string) {
return input_string.trim().length == localization.dateFormat.length;
},
customParseValue(input_value, options) {
const default_time = this.props.defaultTime;
let [res, error] = this.parseValueOriginal(input_value, options);
if (default_time && this.isStrDate(input_value)) {
const new_value = res.set({
hour: default_time.hour,
minute: default_time.minute,
second: default_time.second,
});
res = new_value;
}
return [res, error];
},
initFormat() {
this._super.apply(this, arguments);
this.parseValueOriginal = this.parseValue;
this.parseValue = this.customParseValue;
},
});
DateTimePicker.props = _.extend({}, DateTimePicker.props, {