From 1fa67917ba648bc15f5a895f6bdcea173e2a7258 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Thu, 15 Jun 2017 14:09:11 +0200 Subject: [FIX] web: allow to move cursor in inputs with arrows Commit 9966e4b added calls to preventDefault() on the keydown event for left, right, up and down arrows, to prevent the page from scrolling. However, it also prevents the cursor from moving inside the inputs. Since the initial issue only concerned checkboxes, this rev. moves the preventDefault() calls from AbstractField to FieldBoolean. --- addons/web/static/src/js/fields/basic_fields.js | 5 +++++ 1 file changed, 5 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 d4013a8bcdb..ffe7d7c0f99 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -686,6 +686,11 @@ var FieldBoolean = AbstractField.extend({ this.$input.prop('checked', !this.value); this._setValue(!this.value); return; + case $.ui.keyCode.UP: + case $.ui.keyCode.RIGHT: + case $.ui.keyCode.DOWN: + case $.ui.keyCode.LEFT: + ev.preventDefault(); } this._super.apply(this, arguments); }, -- cgit v1.2.3 From 8859d25bc5b719734b7d02bc26adfd38dca79e56 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Thu, 15 Jun 2017 12:37:42 +0200 Subject: [FIX] web: FieldWidgets: use correct format/parse functions Field widgets must format and parse values according to the widget type, not to the field type. For example, if a monetary field is inserted in a form view with widget="float", the field's value must be formatted with the float formatter, not the montetary one. This wasn't the case before this rev. --- addons/web/static/src/js/fields/basic_fields.js | 85 ++++++------------------- 1 file changed, 21 insertions(+), 64 deletions(-) (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 ffe7d7c0f99..ef1832e00d6 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -321,6 +321,14 @@ var FieldDate = InputField.extend({ tagName: "span", supportedFieldTypes: ['date'], + /** + * @override + */ + init: function () { + this._super.apply(this, arguments); + // use the session timezone when formatting dates + this.formatOptions.timezone = true; + }, /** * In edit mode, instantiates a DateWidget datepicker and listen to changes. * @@ -396,17 +404,6 @@ var FieldDate = InputField.extend({ this.datewidget.setValue(this.value); this.$input = this.datewidget.$input; }, - - /** - * FieldDateTime overrides _formatValue to use the session timezone - * - * @override - * @private - * @param {Moment} value - */ - _formatValue: function (value) { - return field_utils.format.date(value, {timezone: true}); - }, }); var FieldDateTime = FieldDate.extend({ @@ -448,17 +445,6 @@ var FieldDateTime = FieldDate.extend({ this.datewidget.setValue(value); this.$input = this.datewidget.$input; }, - - /** - * FieldDateTime overrides _formatValue to use the session timezone - * - * @override - * @private - * @param {Moment} value - */ - _formatValue: function (value) { - return field_utils.format.datetime(value, {timezone: true}); - }, }); var FieldMonetary = InputField.extend({ @@ -490,6 +476,13 @@ var FieldMonetary = InputField.extend({ this.tagName = 'div'; this.className += ' o_input'; } + + // use the formatFloat function in edit + if (this.mode === 'edit') { + this.formatType = 'float'; + } + this.formatOptions.currency = this.currency; + this.formatOptions.digits = [16, 2]; }, //-------------------------------------------------------------------------- @@ -562,22 +555,6 @@ var FieldMonetary = InputField.extend({ var currencyID = this.record.data[currencyField] && this.record.data[currencyField].res_id; this.currency = session.get_currency(currencyID); }, - /** - * FieldMonetary overrides _formatValue to use the format monetary method - * in readonly. - * - * @override - * @private - * @param {float} value - * @returns {string} - */ - _formatValue: function (value) { - var format = field_utils.format[this.mode === 'edit' ? "float" : "monetary"]; - return format(value, this.field, { - digits: [16, 2], - currency: this.currency, - }); - }, }); var FieldBoolean = AbstractField.extend({ @@ -739,7 +716,7 @@ var FieldInteger = InputField.extend({ } return value; } - return field_utils.format.integer(value, this.field); + return this._super.apply(this, arguments); }, }); @@ -776,31 +753,11 @@ var FieldFloat = InputField.extend({ }); var FieldFloatTime = FieldFloat.extend({ - supportedFieldTypes: ['float'], - - //-------------------------------------------------------------------------- - // Private - //-------------------------------------------------------------------------- - - /** - * Format the float time value into a human-readable time format. - * - * @override - * @private - */ - _formatValue: function (value) { - return field_utils.format.float_time(value); - }, - - /** - * Parse the human-readable formatted time value into a float. - * - * @override - * @private - */ - _parseValue: function (value) { - return field_utils.parse.float_time(value); - }, + // this is not strictly necessary, as for this widget to be used, the 'widget' + // attrs must be set to 'float_time', so the formatType is automatically + // 'float_time', but for the sake of clarity, we explicitely define a + // FieldFloatTime widget with formatType = 'float_time'. + formatType: 'float_time', }); var FieldText = InputField.extend(TranslatableFieldMixin, { -- cgit v1.2.3 From c5f8f35747b4ca9633c664d6be74614c5ce22fcd Mon Sep 17 00:00:00 2001 From: Martin Geubelle Date: Mon, 19 Jun 2017 15:17:05 +0200 Subject: [FIX] web: properly handle tab navigation in readonly The tab navigation was only working in edit mode. Entering a readonly form view with input fields was causing a traceback. As the default browser behaviour has been overriden with custom navigation, we need to specify which widget can be focused (e.g.: url, many2one, etc.). --- addons/web/static/src/js/fields/basic_fields.js | 51 ++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 5 deletions(-) (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 ef1832e00d6..79654cc3095 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -285,11 +285,15 @@ var InputField = DebouncedField.extend({ */ _onNavigationMove: function (ev) { this._super.apply(this, arguments); - var input = this.$input[0]; - var selecting = (input.selectionEnd !== input.selectionStart); - if ((ev.data.direction === "left" && (selecting || input.selectionStart !== 0)) - || (ev.data.direction === "right" && (selecting || input.selectionStart !== input.value.length))) { - ev.stopPropagation(); + + // the following code only makes sense in edit mode, with an input + if (this.mode === 'edit') { + var input = this.$input[0]; + var selecting = (input.selectionEnd !== input.selectionStart); + if ((ev.data.direction === "left" && (selecting || input.selectionStart !== 0)) + || (ev.data.direction === "right" && (selecting || input.selectionStart !== input.value.length))) { + ev.stopPropagation(); + } } }, }); @@ -814,6 +818,19 @@ var FieldEmail = InputField.extend({ this.tagName = this.mode === 'readonly' ? 'a' : 'input'; }, + //-------------------------------------------------------------------------- + // Public + //-------------------------------------------------------------------------- + + /** + * Returns the associated link. + * + * @override + */ + getFocusableElement: function () { + return this.mode === 'readonly' && this.$el || $(); + }, + //-------------------------------------------------------------------------- // Private //-------------------------------------------------------------------------- @@ -849,6 +866,17 @@ var FieldPhone = FieldEmail.extend({ this.tagName = 'span'; } }, + /** + * Returns the associated link only if there is one. + * + * @override + */ + getFocusableElement: function () { + if (this._canCall()) { + return this._super.apply(this, arguments); + } + return $(); + }, //-------------------------------------------------------------------------- // Private @@ -902,6 +930,19 @@ var UrlWidget = InputField.extend({ this.tagName = this.mode === 'readonly' ? 'a' : 'input'; }, + //-------------------------------------------------------------------------- + // Public + //-------------------------------------------------------------------------- + + /** + * Returns the associated link. + * + * @override + */ + getFocusableElement: function () { + return this.mode === 'readonly' && this.$el || $(); + }, + //-------------------------------------------------------------------------- // Private //-------------------------------------------------------------------------- -- cgit v1.2.3 From 28b67ee7dcc29cf85722d18d971fd2a9cc439093 Mon Sep 17 00:00:00 2001 From: Martin Geubelle Date: Tue, 20 Jun 2017 10:26:18 +0200 Subject: [FIX] web: properly handle tab navigation with widgets in edit Rev. https://github.com/odoo/odoo/commit/c5f8f35747b4ca9633c664d6be74614c5ce22fcd introduced a regression: the input of widgets 'email' and 'url' was not correctly focused anymore with tab navigation. The method `getFocusableElement` on their common parent (`InputField`) has not been correctly overriden because `_super``was not called in edit mode. --- addons/web/static/src/js/fields/basic_fields.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (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 79654cc3095..103509a7b53 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -828,7 +828,7 @@ var FieldEmail = InputField.extend({ * @override */ getFocusableElement: function () { - return this.mode === 'readonly' && this.$el || $(); + return this.mode === 'readonly' ? this.$el : this._super.apply(this, arguments); }, //-------------------------------------------------------------------------- @@ -940,7 +940,7 @@ var UrlWidget = InputField.extend({ * @override */ getFocusableElement: function () { - return this.mode === 'readonly' && this.$el || $(); + return this.mode === 'readonly' ? this.$el : this._super.apply(this, arguments); }, //-------------------------------------------------------------------------- -- cgit v1.2.3 From 378efa14449baeb19a8fb6a810b8db148971c0c1 Mon Sep 17 00:00:00 2001 From: David Monjoie Date: Fri, 23 Jun 2017 15:36:09 +0200 Subject: [FIX] web: update filename correctly in binary fields The update_field event is not used anymore so it needs to trigger a field_changed instead. --- addons/web/static/src/js/fields/basic_fields.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (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 103509a7b53..82970255b3e 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -1044,7 +1044,13 @@ var AbstractFieldBinary = AbstractField.extend({ set_filename: function (value) { var filename = this.attrs.filename; if (filename && filename in this.fields) { - this.trigger_up('update_field', { name: filename, value: value }); + var changes = {}; + changes[filename] = value; + this.trigger_up('field_changed', { + dataPointID: this.dataPointID, + changes: changes, + viewType: this.viewType, + }); } }, on_clear: function () { -- cgit v1.2.3