From 1c59de867dd04ae7aa2b6625d4f1c5c877b7586f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Theys?= Date: Tue, 28 Aug 2018 11:58:52 +0200 Subject: [FIX] web: prevent handle from crashing with text field 289adeb63f51a9af26b8f383ba80089aa7aa6d87 introduced a bug where we tried to trigger an event on an element that didn't exist. Indeed there is no input if it's not in edit mode. This commit fixes it. PR: none Task: none --- addons/web/static/src/js/fields/basic_fields.js | 4 +++- 1 file changed, 3 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 ed393d667b7..00a4532c2e1 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -1079,7 +1079,9 @@ var FieldText = InputField.extend(TranslatableFieldMixin, { reset: function () { var self = this; return $.when(this._super.apply(this, arguments)).then(function () { - self.$input.trigger('change'); + if (self.mode === 'edit') { + self.$input.trigger('change'); + } }); }, //-------------------------------------------------------------------------- -- cgit v1.2.3 From 9e6e0da06f48006d1ad046fcc5ea15ac63ad91f1 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Thu, 23 Aug 2018 12:07:57 +0200 Subject: [FIX] web: accept false value in comparison momentjs `isSame` method considers undefined values but not false our method _isSameValue does consider false Correct the error when running web tests Deprecation warning: value provided is not in a recognized ISO format --- addons/web/static/src/js/fields/basic_fields.js | 2 +- 1 file changed, 1 insertion(+), 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 ee52f4a27e5..61b13be7be5 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -417,7 +417,7 @@ var FieldDate = InputField.extend({ this.datewidget = this._makeDatePicker(); this.datewidget.on('datetime_changed', this, function () { var value = this._getValue(); - if ((!value && this.value) || (value && !value.isSame(this.value))) { + if ((!value && this.value) || (value && !this._isSameValue(value))) { this._setValue(value); } }); -- cgit v1.2.3 From 68332a0177990020f11b94317a6d3a81ff906d69 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Fri, 17 Aug 2018 13:39:29 +0200 Subject: [FIX] web: fix evaluation context of the domain selector The domain was instantiated without being given any evaluation context. As a result, the uid variable was not defined, crashing the js if present in a user-defined filter. opw 1866852 --- addons/web/static/src/js/fields/basic_fields.js | 5 ++--- 1 file changed, 2 insertions(+), 3 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 61b13be7be5..d624651ac85 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -2264,19 +2264,18 @@ var FieldDomain = AbstractField.extend({ // Convert char value to array value var value = this.value || "[]"; - var domain = Domain.prototype.stringToArray(value); // Create the domain selector or change the value of the current one... var def; if (!this.domainSelector) { - this.domainSelector = new DomainSelector(this, this._domainModel, domain, { + this.domainSelector = new DomainSelector(this, this._domainModel, value, { readonly: this.mode === "readonly" || this.inDialog, filters: this.fsFilters, debugMode: session.debug, }); def = this.domainSelector.prependTo(this.$el); } else { - def = this.domainSelector.setDomain(domain); + def = this.domainSelector.setDomain(value); } // ... then replace the other content (matched records, etc) return def.then(this._replaceContent.bind(this)); -- cgit v1.2.3 From 74fcd3ac3b0445c5fc0d9239900a9a41bfd04de8 Mon Sep 17 00:00:00 2001 From: svs-odoo Date: Tue, 4 Sep 2018 13:44:46 +0200 Subject: [IMP] web: FieldInteger and FieldFloat can use input of type number This allow the browser/device to handle the experience of handling number in a more native way. FieldInteger and FieldFloat now inherits from NumericField because we want to format it or not dependent of the view (readonly or edit) and the NumericField will manage it. We do that because input type number can't take a value with comma on Chrome (FireFox is more permissive but not perfect because comma is the separator for decimal in this case). Task #1880376 --- addons/web/static/src/js/fields/basic_fields.js | 91 +++++++++++++++++-------- 1 file changed, 61 insertions(+), 30 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 00a4532c2e1..243a28bb937 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -346,6 +346,64 @@ var InputField = DebouncedField.extend({ }, }); +var NumericField = InputField.extend({ + tagName: 'span', + + //-------------------------------------------------------------------------- + // Public + //-------------------------------------------------------------------------- + + /** + * For numeric fields, 0 is a valid value. + * + * @override + */ + isSet: function () { + return this.value === 0 || this._super.apply(this, arguments); + }, + + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * Format numerical value (integer or float) + * + * Note: We have to overwrite this method to skip the format if we are into + * edit mode on a input type number. + * + * @override + * @private + */ + _formatValue: function (value) { + if (this.mode === 'edit' && this.nodeOptions.type === 'number') { + return value; + } + return this._super.apply(this, arguments); + }, + + /** + * Formats an input element for edit mode. This is in a separate function so + * extending widgets can use it on their input without having input as tagName. + * + * Note: We have to overwrite this method to set the input's type to number if + * option setted into the field. + * + * @override + * @private + */ + _prepareInput: function ($input) { + var result = this._super.apply(this, arguments); + if (this.nodeOptions.type === 'number') { + this.$input.attr({type: 'number'}); + } + if (this.nodeOptions.step) { + this.$input.attr({step: this.nodeOptions.step}); + } + return result; + } +}); + var FieldChar = InputField.extend(TranslatableFieldMixin, { className: 'o_field_char', tagName: 'span', @@ -811,24 +869,10 @@ var FieldBoolean = AbstractField.extend({ }, }); -var FieldInteger = InputField.extend({ +var FieldInteger = NumericField.extend({ className: 'o_field_integer o_field_number', - tagName: 'span', supportedFieldTypes: ['integer'], - //-------------------------------------------------------------------------- - // Public - //-------------------------------------------------------------------------- - - /** - * For integer fields, 0 is a valid value. - * - * @override - */ - isSet: function () { - return this.value === 0 || this._super.apply(this, arguments); - }, - //-------------------------------------------------------------------------- // Private //-------------------------------------------------------------------------- @@ -858,9 +902,8 @@ var FieldInteger = InputField.extend({ }, }); -var FieldFloat = InputField.extend({ +var FieldFloat = NumericField.extend({ className: 'o_field_float o_field_number', - tagName: 'span', supportedFieldTypes: ['float'], /** @@ -875,19 +918,6 @@ var FieldFloat = InputField.extend({ this.nodeOptions.digits = JSON.parse(this.attrs.digits); } }, - - //-------------------------------------------------------------------------- - // Public - //-------------------------------------------------------------------------- - - /** - * For float fields, 0 is a valid value. - * - * @override - */ - isSet: function () { - return this.value === 0 || this._super.apply(this, arguments); - }, }); var FieldFloatTime = FieldFloat.extend({ @@ -2884,6 +2914,7 @@ return { FieldToggleBoolean: FieldToggleBoolean, HandleWidget: HandleWidget, InputField: InputField, + NumericField: NumericField, AttachmentImage: AttachmentImage, LabelSelection: LabelSelection, StateSelectionWidget: StateSelectionWidget, -- cgit v1.2.3