lp bug: https://launchpad.net/bugs/838924 fixed
bzr revid: fme@openerp.com-
20110907163315-b014e9pulr3nsqt4
openerp.web.form.FieldSelection = openerp.web.form.Field.extend({
init: function(view, node) {
openerp.web.form.FieldSelection = openerp.web.form.Field.extend({
init: function(view, node) {
this._super(view, node);
this.template = "FieldSelection";
this._super(view, node);
this.template = "FieldSelection";
- this.field_index = _.map(this.field.selection, function(x, index) {
- return {"ikey": "" + index, "ekey": x[0], "label": x[1]};
+ this.values = this.field.selection;
+ _.each(this.values, function(v, i) {
+ if (v[0] === false && v[1] === '') {
+ self.values.splice(i, 1);
+ }
+ this.values.unshift([false, '']);
},
start: function() {
// Flag indicating whether we're in an event chain containing a change
},
start: function() {
// Flag indicating whether we're in an event chain containing a change
value = value === null ? false : value;
value = value instanceof Array ? value[0] : value;
this._super(value);
value = value === null ? false : value;
value = value instanceof Array ? value[0] : value;
this._super(value);
- var option = _.detect(this.field_index, function(x) {return x.ekey === value;});
- this.$element.find('select').val(option === undefined ? '' : option.ikey);
+ var index = 0;
+ 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();
- var option = _.detect(this.field_index, function(x) {return x.ikey === ikey;});
- this.value = option === undefined ? false : option.ekey;
+ this.value = this.values[this.$element.find('select')[0].selectedIndex][0];
this._super();
},
update_dom: function() {
this._super();
},
update_dom: function() {
this.$element.find('select').attr('disabled', this.readonly);
},
validate: function() {
this.$element.find('select').attr('disabled', this.readonly);
},
validate: function() {
- var ikey = this.$element.find('select').val();
- var option = _.detect(this.field_index, function(x) {return x.ikey === ikey;});
- this.invalid = this.required && (option === undefined || option.ekey === false);
+ var value = this.values[this.$element.find('select')[0].selectedIndex];
+ this.invalid = !(value && !(this.required && value[0] === false));
},
focus: function() {
this.$element.find('select').focus();
},
focus: function() {
this.$element.find('select').focus();
t-att-id="widget.element_id + '_field'"
t-att-class="'field_' + widget.type"
style="width: 100%">
t-att-id="widget.element_id + '_field'"
t-att-class="'field_' + widget.type"
style="width: 100%">
- <t t-foreach="widget.field_index" t-as="options">
- <option t-att-value="options.ikey">
- <t t-esc="options.label"/>
- </option>
+ <t t-foreach="widget.values" t-as="option">
+ <option><t t-esc="option[1]"/></option>