diff options
| author | Lucas Perais (lpe) <lpe@odoo.com> | 2019-08-22 16:06:02 +0000 |
|---|---|---|
| committer | Lucas Perais (lpe) <lpe@odoo.com> | 2019-08-23 14:29:05 +0000 |
| commit | d310cd447850d8451b9b51b0e3b6243734cddaef (patch) | |
| tree | 645fde1b601db3bddf45e03af217876f35ca8643 /addons/web/static/src/js/fields/relational_fields.js | |
| parent | f01c325e9a42ca56cf9e7825a6251739410cc2f9 (diff) | |
[FIX] web: selection: required, option present but disabled
Before this commit, a field selection which was required
did not have an empty option
ref: 4dfabb8f7adde06a7936502af61534c9958ed4f7
This is fine, but overlooked the fact that modules can modify
the required attribute, or even views can do it
So, we may end up in a situation where the field is required but set to false
This configuration is problematic, at least for the timezone selection field
(see OPW)
After this commit, the empty option is just not visible
note that `disabled = True` would not work because val is not accessible
Because of commits:
- 4dfabb8f7adde06a7936502af61534c9958ed4f7 for the selection feature
- d77ce4c2a92c1da48150e4e84b714dd93f64847d overriding the required attribute of tz in res.user form
OPW 2057913
closes odoo/odoo#35989
Signed-off-by: Lucas Perais (lpe) <lpe@odoo.com>
Diffstat (limited to 'addons/web/static/src/js/fields/relational_fields.js')
| -rw-r--r-- | addons/web/static/src/js/fields/relational_fields.js | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js index 0f247ba3a8d..13e58095d40 100644 --- a/addons/web/static/src/js/fields/relational_fields.js +++ b/addons/web/static/src/js/fields/relational_fields.js @@ -2471,10 +2471,14 @@ var FieldSelection = AbstractField.extend({ */ _renderEdit: function () { this.$el.empty(); + var required = this.attrs.modifiersValue && this.attrs.modifiersValue.required; for (var i = 0 ; i < this.values.length ; i++) { + var disabled = required && this.values[i][0] === false; + this.$el.append($('<option/>', { value: JSON.stringify(this.values[i][0]), - text: this.values[i][1] + text: this.values[i][1], + style: disabled ? "display: none" : "", })); } var value = this.value; @@ -2513,9 +2517,7 @@ var FieldSelection = AbstractField.extend({ return v[0] === false && v[1] === ''; }); } - if (!this.attrs.modifiersValue || !this.attrs.modifiersValue.required) { - this.values = [[false, this.attrs.placeholder || '']].concat(this.values); - } + this.values = [[false, this.attrs.placeholder || '']].concat(this.values); }, //-------------------------------------------------------------------------- |
