diff --git a/web_widget_numeric_step/__manifest__.py b/web_widget_numeric_step/__manifest__.py index 8618e7c86..efc3a37e4 100644 --- a/web_widget_numeric_step/__manifest__.py +++ b/web_widget_numeric_step/__manifest__.py @@ -5,7 +5,7 @@ { 'name': "Web Widget Numeric Step", 'category': "web", - 'version': "12.0.1.1.0", + 'version': "12.0.1.1.1", 'author': "GRAP, Tecnativa, " "Odoo Community Association (OCA)", 'license': 'AGPL-3', diff --git a/web_widget_numeric_step/static/src/js/numeric_step.js b/web_widget_numeric_step/static/src/js/numeric_step.js index b49b3a3ab..46310fa68 100644 --- a/web_widget_numeric_step/static/src/js/numeric_step.js +++ b/web_widget_numeric_step/static/src/js/numeric_step.js @@ -13,13 +13,14 @@ odoo.define('web_widget_numeric_step.field', function (require) { var NumericStep = FieldFloat.extend({ template: 'web_widget_numeric_step', className: 'o_field_numeric_step o_field_number', - events: _.extend({}, FieldFloat.prototype.events, { + events: _.extend({}, _.omit(FieldFloat.prototype.events, ['change', 'input']), { 'mousedown .btn_numeric_step': '_onStepMouseDown', 'touchstart .btn_numeric_step': '_onStepMouseDown', 'click .btn_numeric_step': '_onStepClick', 'wheel .input_numeric_step': '_onWheel', 'keydown .input_numeric_step': '_onKeyDown', 'change .input_numeric_step': '_onChange', + 'input .input_numeric_step': '_onInput', }), supportedFieldTypes: ['float', 'integer'], @@ -28,6 +29,10 @@ odoo.define('web_widget_numeric_step.field', function (require) { MIN_DELAY: 50, SUBSTRACT_DELAY_STEP: 25, + DELAY_THROTTLE_CHANGE: 200, + + _prevValue: null, // Used to know if the value was really changed + init: function () { this._super.apply(this, arguments); @@ -44,6 +49,11 @@ odoo.define('web_widget_numeric_step.field', function (require) { 'min': Number(min_val), 'max': Number(max_val), }; + + var self = this; + this._lazyOnChangeTrigger = _.debounce(function() { + self.$input.trigger("change"); + }, this.DELAY_THROTTLE_CHANGE); }, /** @@ -132,12 +142,14 @@ odoo.define('web_widget_numeric_step.field', function (require) { } else if (mode === 'minus') { cval -= this._config.step; } - this.$input.val(this._sanitizeNumberValue(cval)); - this.isDirty = true; - this._doDebouncedAction(); - // Every time that user update the value we must trigger an - // onchange method. - this.$input.trigger("change"); + var nval = this._sanitizeNumberValue(cval); + if (nval !== this._prevValue) { + this.$input.val(nval); + // Every time that user update the value we must trigger an + // onchange method. + this._lazyOnChangeTrigger(); + } + this._prevValue = nval; }, // Handle Events @@ -201,12 +213,11 @@ odoo.define('web_widget_numeric_step.field', function (require) { /** * Sanitize user input value * - * @param {ChangeEvent} ev + * @override */ _onChange: function (ev) { ev.target.value = this._sanitizeNumberValue(ev.target.value); - // Call _onChange of input widget - this._super.apply(this, arguments); + return this._super.apply(this, arguments); }, // Helper Functions