[FIX] Fixed FieldSelection problems with false values
lp bug: https://launchpad.net/bugs/838924 fixed bzr revid: fme@openerp.com-20110907163315-b014e9pulr3nsqt4
This commit is contained in:
parent
43a788378d
commit
9b18066adc
|
@ -1251,11 +1251,16 @@ openerp.web.form.FieldTextXml = openerp.web.form.Field.extend({
|
||||||
|
|
||||||
openerp.web.form.FieldSelection = openerp.web.form.Field.extend({
|
openerp.web.form.FieldSelection = openerp.web.form.Field.extend({
|
||||||
init: function(view, node) {
|
init: function(view, node) {
|
||||||
|
var self = this;
|
||||||
this._super(view, node);
|
this._super(view, node);
|
||||||
this.template = "FieldSelection";
|
this.template = "FieldSelection";
|
||||||
this.field_index = _.map(this.field.selection, function(x, index) {
|
this.values = this.field.selection;
|
||||||
return {"ikey": "" + index, "ekey": x[0], "label": x[1]};
|
_.each(this.values, function(v, i) {
|
||||||
|
if (v[0] === false && v[1] === '') {
|
||||||
|
self.values.splice(i, 1);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
this.values.unshift([false, '']);
|
||||||
},
|
},
|
||||||
start: function() {
|
start: function() {
|
||||||
// Flag indicating whether we're in an event chain containing a change
|
// Flag indicating whether we're in an event chain containing a change
|
||||||
|
@ -1285,13 +1290,14 @@ openerp.web.form.FieldSelection = openerp.web.form.Field.extend({
|
||||||
value = value === null ? false : value;
|
value = value === null ? false : value;
|
||||||
value = value instanceof Array ? value[0] : value;
|
value = value instanceof Array ? value[0] : value;
|
||||||
this._super(value);
|
this._super(value);
|
||||||
var option = _.detect(this.field_index, function(x) {return x.ekey === value;});
|
var index = 0;
|
||||||
this.$element.find('select').val(option === undefined ? '' : option.ikey);
|
for (var i = 0, ii = this.values.length; i < ii; i++) {
|
||||||
|
if (this.values[i][0] === value) index = i;
|
||||||
|
}
|
||||||
|
this.$element.find('select')[0].selectedIndex = index;
|
||||||
},
|
},
|
||||||
set_value_from_ui: function() {
|
set_value_from_ui: function() {
|
||||||
var ikey = this.$element.find('select').val();
|
this.value = this.values[this.$element.find('select')[0].selectedIndex][0];
|
||||||
var option = _.detect(this.field_index, function(x) {return x.ikey === ikey;});
|
|
||||||
this.value = option === undefined ? false : option.ekey;
|
|
||||||
this._super();
|
this._super();
|
||||||
},
|
},
|
||||||
update_dom: function() {
|
update_dom: function() {
|
||||||
|
@ -1299,9 +1305,8 @@ openerp.web.form.FieldSelection = openerp.web.form.Field.extend({
|
||||||
this.$element.find('select').attr('disabled', this.readonly);
|
this.$element.find('select').attr('disabled', this.readonly);
|
||||||
},
|
},
|
||||||
validate: function() {
|
validate: function() {
|
||||||
var ikey = this.$element.find('select').val();
|
var value = this.values[this.$element.find('select')[0].selectedIndex];
|
||||||
var option = _.detect(this.field_index, function(x) {return x.ikey === ikey;});
|
this.invalid = !(value && !(this.required && value[0] === false));
|
||||||
this.invalid = this.required && (option === undefined || option.ekey === false);
|
|
||||||
},
|
},
|
||||||
focus: function() {
|
focus: function() {
|
||||||
this.$element.find('select').focus();
|
this.$element.find('select').focus();
|
||||||
|
|
|
@ -799,10 +799,8 @@
|
||||||
t-att-id="widget.element_id + '_field'"
|
t-att-id="widget.element_id + '_field'"
|
||||||
t-att-class="'field_' + widget.type"
|
t-att-class="'field_' + widget.type"
|
||||||
style="width: 100%">
|
style="width: 100%">
|
||||||
<t t-foreach="widget.field_index" t-as="options">
|
<t t-foreach="widget.values" t-as="option">
|
||||||
<option t-att-value="options.ikey">
|
<option><t t-esc="option[1]"/></option>
|
||||||
<t t-esc="options.label"/>
|
|
||||||
</option>
|
|
||||||
</t>
|
</t>
|
||||||
</select>
|
</select>
|
||||||
</t>
|
</t>
|
||||||
|
|
Loading…
Reference in New Issue