From a5cca2cda3b5dc9468961fe7bebeb1257d67ecdd Mon Sep 17 00:00:00 2001 From: "Michael Mattiello (mcm)" Date: Mon, 3 Aug 2020 12:17:25 +0000 Subject: [IMP] web: add smart date input on date field This commit adds smart date inputs for date and datetime fields. The goal of smart date input is to provide the user some shortcuts when setting dates. The rule is [+-]\d+[dwmy]? So we can enter inputs like: +3 to have today + 3 days -2w to have today - 2 weeks +1y to have today + 1 year +5m to have today + 5 months -4d to have today - 4 days closes odoo/odoo#55602 Task: 2270347 Signed-off-by: Aaron Bohy (aab) --- addons/web/static/src/js/fields/basic_fields.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'addons/web/static/src/js/fields/basic_fields.js') diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js index 8657e44c49b..252ef70894e 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -863,6 +863,25 @@ var FieldDate = InputField.extend({ this.datewidget.setValue(this.value); this.$input = this.datewidget.$input; }, + + //-------------------------------------------------------------------------- + // Handlers + //-------------------------------------------------------------------------- + + /** + * Confirm the value on hit enter and re-render + * + * @private + * @override + * @param {KeyboardEvent} ev + */ + async _onKeydown(ev) { + this._super(...arguments); + if (ev.which === $.ui.keyCode.ENTER) { + await this._setValue(this.$input.val()); + this._render(); + } + }, }); var FieldDateTime = FieldDate.extend({ -- cgit v1.2.3