Merge PR #1543 into 12.0

Signed-off-by pedrobaeza
This commit is contained in:
OCA-git-bot
2020-03-06 12:09:30 +00:00

View File

@@ -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,9 +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();
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
@@ -198,10 +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);
return this._super.apply(this, arguments);
},
// Helper Functions