Browse Source

[12.0][IMP] web_widget_color: Allow non-required fields

pull/1270/head
Alexandre Díaz 6 years ago
parent
commit
d103075462
  1. 26
      web_widget_color/static/src/js/widget.js
  2. 2
      web_widget_color/static/src/xml/widget.xml

26
web_widget_color/static/src/js/widget.js

@ -1,10 +1,11 @@
/* Global jscolor */
odoo.define('web.web_widget_color', function(require) {
/* global jscolor */
odoo.define('web.web_widget_color', function (require) {
"use strict";
var basic_fields = require('web.basic_fields');
var field_registry = require('web.field_registry');
var ListRenderer = require('web.ListRenderer');
var pyUtils = require('web.py_utils');
var FieldColor = basic_fields.FieldChar.extend({
template: 'FieldColor',
@ -14,9 +15,19 @@ odoo.define('web.web_widget_color', function(require) {
// Do Nothing
},
_renderEdit: function() {
_renderEdit: function () {
var isRequired = false;
if ('required' in this.attrs) {
isRequired = pyUtils.py_eval(this.attrs.required);
} else {
isRequired = this.field.required;
}
this.$input = this.$el.find('input');
this.jscolor = new jscolor(this.$input[0], {hash:true, zIndex: 2000});
this.jscolor = new jscolor(this.$input[0], {
hash: true,
zIndex: 2000,
required: isRequired,
});
},
});
field_registry.add('color', FieldColor);
@ -30,15 +41,16 @@ odoo.define('web.web_widget_color', function(require) {
var recordWidgets = this.allFieldWidgets[record.id];
canUnselect = !_.some(recordWidgets, function (widget) {
var $el = widget.getFocusableElement();
return ($el instanceof jQuery && $el.hasClass('jscolor-active'));
return $el instanceof jQuery &&
$el.hasClass('jscolor-active');
});
}
if (canUnselect) {
return this._super.apply(this, arguments);
} else {
return $.Deferred().resolve();
}
return $.Deferred().resolve();
},
});

2
web_widget_color/static/src/xml/widget.xml

@ -8,7 +8,7 @@
t-att-autofocus="widget.attrs.autofocus"
t-att-placeholder="widget.attrs.placeholder"
t-att-maxlength="widget.field.size"
t-att-value="widget.value"
t-att-value="widget.value or ''"
class="o_input"
t-if="widget.mode !== 'readonly'"/>
<t t-else="">

Loading…
Cancel
Save