diff options
| author | Romain Derie <rde@odoo.com> | 2020-10-22 09:53:34 +0000 |
|---|---|---|
| committer | Romain Derie <rde@odoo.com> | 2020-11-05 14:18:52 +0000 |
| commit | bcfbc3ea11814931c5d1f8ce3c44b1756bbfc439 (patch) | |
| tree | 6569d6da10618c779c278fc9e2fb2e86f8a75d17 /addons/web | |
| parent | 631030ae179c65ae0d99603046b5a09ffe00c408 (diff) | |
[FIX] web: prevent crashes from tempusdominus
The BS4 tempusdominus lib has 2 issues within Odoo:
1. On wrong string formating (eg typing "33"), the lib would trigger its own
error "datetimepicker.error" that would be catch in our crash manager making
it display a modal error.
This is generally handled by catching that event and preventing it to bubble
to the crash manager, see:
Datepicker widget: https://github.com/odoo/odoo/blame/00b61c752e2cf514fdfb291ee36344e5af3b04dc/addons/web/static/src/js/widgets/date_picker.js#L128
OWL datepicker widget: https://github.com/odoo/odoo/blame/00b61c752e2cf514fdfb291ee36344e5af3b04dc/addons/web/static/src/js/components/datepicker.js#L43
Snippets options: https://github.com/odoo/odoo/blame/00b61c752e2cf514fdfb291ee36344e5af3b04dc/addons/web_editor/static/src/js/editor/snippets.options.js#L1646
2. If there is a valid date, and an user enter an unvalid date, the lib crashed
by throwing `Cannot read property 'format' of undefined'`.
Datepicker widget: https://github.com/odoo/odoo/blame/00b61c752e2cf514fdfb291ee36344e5af3b04dc/addons/web/static/src/js/widgets/date_picker.js#L94 (fbbfa6ddca and 5481c429efb)
OWL datepicker widget: https://github.com/odoo/odoo/blame/00b61c752e2cf514fdfb291ee36344e5af3b04dc/addons/web/static/src/js/components/datepicker.js#L149
Snippets options: https://github.com/odoo/odoo/blame/00b61c752e2cf514fdfb291ee36344e5af3b04dc/addons/web_editor/static/src/js/editor/snippets.options.js#L1617
Note that the issue was reported at https://github.com/tempusdominus/bootstrap-4/issues/223
Those errors can be seen for instance in Page Properties dialog (publish date
field) and in the form builder snippet if you add a date(time) field.
task-2335403
closes odoo/odoo#60514
Signed-off-by: Romain Derie <rdeodoo@users.noreply.github.com>
Diffstat (limited to 'addons/web')
| -rw-r--r-- | addons/web/static/lib/tempusdominus/tempusdominus.js | 2 | ||||
| -rw-r--r-- | addons/web/static/src/js/public/public_root.js | 11 |
2 files changed, 12 insertions, 1 deletions
diff --git a/addons/web/static/lib/tempusdominus/tempusdominus.js b/addons/web/static/lib/tempusdominus/tempusdominus.js index 80619bfe2da..6a1d9544fec 100644 --- a/addons/web/static/lib/tempusdominus/tempusdominus.js +++ b/addons/web/static/lib/tempusdominus/tempusdominus.js @@ -490,7 +490,7 @@ var DateTimePicker = function ($, moment) { DateTimePicker.prototype._change = function _change(e) { var val = $(e.target).val().trim(), parsedDate = val ? this._parseInputDate(val) : null; - this._setValue(parsedDate); + this._setValue(parsedDate, 0); // Odoo FIX: if a valid date is replaced by an invalid one, lib will crash, see https://github.com/tempusdominus/bootstrap-4/issues/223 e.stopImmediatePropagation(); return false; }; diff --git a/addons/web/static/src/js/public/public_root.js b/addons/web/static/src/js/public/public_root.js index f684df2b629..93e1c4fd92e 100644 --- a/addons/web/static/src/js/public/public_root.js +++ b/addons/web/static/src/js/public/public_root.js @@ -84,6 +84,8 @@ var PublicRoot = publicWidget.RootWidget.extend({ $('input, textarea').placeholder(); } + this.$el.children().on('error.datetimepicker', this._onDateTimePickerError.bind(this)); + return Promise.all(defs); }, @@ -316,6 +318,15 @@ var PublicRoot = publicWidget.RootWidget.extend({ _onDisableOnClick: function (ev) { $(ev.currentTarget).addClass('disabled'); }, + /** + * Library clears the wrong date format so just ignore error + * + * @private + * @param {Event} ev + */ + _onDateTimePickerError: function (ev) { + return false; + }, }); return { |
