From 160a39c4097e0a1baa6c42c69e176c0e1840df5a Mon Sep 17 00:00:00 2001 From: David Date: Fri, 12 Jul 2024 13:22:29 +0200 Subject: [PATCH] [IMP] web_widget_numeric_step: option to add classes New option so we can add new classes to the input or remove existing ones so we can style the input at our will. TT49390 --- web_widget_numeric_step/README.rst | 4 +++- web_widget_numeric_step/readme/USAGE.rst | 2 ++ web_widget_numeric_step/static/description/index.html | 4 +++- web_widget_numeric_step/static/src/js/numeric_step.js | 9 ++++++++- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/web_widget_numeric_step/README.rst b/web_widget_numeric_step/README.rst index 7a77623bb..57338beb9 100644 --- a/web_widget_numeric_step/README.rst +++ b/web_widget_numeric_step/README.rst @@ -7,7 +7,7 @@ Web Widget Numeric Step !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:a2b6cac785e6c68124e9b96656216e49d609e2af60effef85a069ee295d3bc41 + !! source digest: sha256:3f4e1a0c2c047ce2fc2dcc1f2b9bd928cf1c5c5a26f131d17b64d3f5b98459ad !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png @@ -65,6 +65,8 @@ Example for an 0.25 step, min to -1 and max to 10 : - max > Max. value allowed (default: no limit) - auto_select > Select the content when the element get focus (default: False) - placeholder > Define the placeholder text (default: None) +- add_class > Define additional classes for the input (default: None) +- remove_class > Remove default classes from the input (default: None) **Examples** diff --git a/web_widget_numeric_step/readme/USAGE.rst b/web_widget_numeric_step/readme/USAGE.rst index fabb69723..42f8cf1ff 100644 --- a/web_widget_numeric_step/readme/USAGE.rst +++ b/web_widget_numeric_step/readme/USAGE.rst @@ -22,6 +22,8 @@ Example for an 0.25 step, min to -1 and max to 10 : - max > Max. value allowed (default: no limit) - auto_select > Select the content when the element get focus (default: False) - placeholder > Define the placeholder text (default: None) +- add_class > Define additional classes for the input (default: None) +- remove_class > Remove default classes from the input (default: None) **Examples** diff --git a/web_widget_numeric_step/static/description/index.html b/web_widget_numeric_step/static/description/index.html index b676e0002..f925e9a52 100644 --- a/web_widget_numeric_step/static/description/index.html +++ b/web_widget_numeric_step/static/description/index.html @@ -367,7 +367,7 @@ ul.auto-toc { !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:a2b6cac785e6c68124e9b96656216e49d609e2af60effef85a069ee295d3bc41 +!! source digest: sha256:3f4e1a0c2c047ce2fc2dcc1f2b9bd928cf1c5c5a26f131d17b64d3f5b98459ad !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

Beta License: AGPL-3 OCA/web Translate me on Weblate Try me on Runboat

This widget changes input number field and make it easier to increment the number thanks to 2 buttons (+ and -). @@ -407,6 +407,8 @@ Iteration step by default is 1.

  • max > Max. value allowed (default: no limit)
  • auto_select > Select the content when the element get focus (default: False)
  • placeholder > Define the placeholder text (default: None)
  • +
  • add_class > Define additional classes for the input (default: None)
  • +
  • remove_class > Remove default classes from the input (default: None)
  • Examples

    Iteration with 0.25 step, min to -1 and max to 10.

    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 8c166fe7a..73694c927 100644 --- a/web_widget_numeric_step/static/src/js/numeric_step.js +++ b/web_widget_numeric_step/static/src/js/numeric_step.js @@ -49,12 +49,13 @@ odoo.define("web_widget_numeric_step.field", function (require) { min_val = this.nodeOptions.max; max_val = this.nodeOptions.min; } - this._config = { step: Number(this.nodeOptions.step) || 1, min: Number(min_val), max: Number(max_val), autoSelect: this.nodeOptions.auto_select, + addClasses: this.nodeOptions.add_class, + removeClasses: this.nodeOptions.remove_class, }; this._lazyOnChangeTrigger = _.debounce( @@ -139,6 +140,12 @@ odoo.define("web_widget_numeric_step.field", function (require) { .addClass("numeric_step_editing_cell") ); this._prepareInput(this.$el.find("input.input_numeric_step")); + if (this._config.addClasses) { + this.$input.addClass(this._config.addClasses); + } + if (this._config.removeClasses) { + this.$input.removeClass(this._config.removeClasses); + } }, /**