diff options
| author | Michael Mattiello (mcm) <mcm@odoo.com> | 2020-01-27 07:17:49 +0000 |
|---|---|---|
| committer | Michael Mattiello (mcm) <mcm@odoo.com> | 2020-02-06 11:55:13 +0000 |
| commit | c5e34d77f5d84c1811e29cabdffdd408695d1d2d (patch) | |
| tree | f083b7a8f74fe322be91a2bfcdbb40d8aab5ad35 /addons/web/static/src/js/fields/basic_fields.js | |
| parent | 9d85bce7db59ebf8cb65c2aa13524fdc69944eb2 (diff) | |
[IMP] web: show % symbol outside the input in percentage widget
Before this commit the % symbol was part of the input. We could write a
value with the % symbol to divide the value by 100 (50% = 0.5, 50 = 50)
This commit removes the % symbol from the input and adds it in a span
after the input so we do not need to write the % symbol anymore.
The value from the input will be saved as $value / 100 in database.
task-2065078
closes odoo/odoo#43995
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
Diffstat (limited to 'addons/web/static/src/js/fields/basic_fields.js')
| -rw-r--r-- | addons/web/static/src/js/fields/basic_fields.js | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js index f2c44891ea2..4aac42db13b 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -1325,8 +1325,41 @@ var FieldFloatToggle = AbstractField.extend({ }); var FieldPercentage = FieldFloat.extend({ + className: 'o_field_float_percentage o_field_number', description: _lt("Percentage"), - formatType:'percentage', + + /** + * @constructor + */ + init() { + this._super(...arguments); + if (this.mode === 'edit') { + this.tagName = 'div'; + this.className += ' o_input'; + + // do not display % in the input in edit + this.formatOptions.noSymbol = true; + } + }, + + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * For percentage widget, the input is inside a div, alongside a span + * containing the percentage(%) symbol. + * + * @override + * @private + */ + _renderEdit() { + this.$el.empty(); + // Prepare and add the input + this._prepareInput(this.$input).appendTo(this.$el); + const $percentageSymbol = $('<span>', { text: '%' }); + this.$el.append($percentageSymbol); + }, }); var FieldText = InputField.extend(TranslatableFieldMixin, { |
