summaryrefslogtreecommitdiff
path: root/addons/web/static/src
diff options
context:
space:
mode:
authorniv-openerp <nicolas.vanhoren@openerp.com>2013-10-28 16:00:19 +0100
committerniv-openerp <nicolas.vanhoren@openerp.com>2013-10-28 16:00:19 +0100
commit7c3ae6a157efaecf8fffea4d3eb9732d3826e531 (patch)
tree605d3d88e6a87c60c214bae6ca7c6fa55c2b4175 /addons/web/static/src
parenta7ff75f94a168e26b9e9a208167b07d45dc751cb (diff)
[FIX] Rare problem in select fields related to previous improvement in that widget.
Sometimes, the value of the field was resetted to false. bzr revid: nicolas.vanhoren@openerp.com-20131028150019-i0nllpqu1i7wpxbr
Diffstat (limited to 'addons/web/static/src')
-rw-r--r--addons/web/static/src/js/view_form.js34
-rw-r--r--addons/web/static/src/xml/base.xml7
2 files changed, 17 insertions, 24 deletions
diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js
index 1fa7cb6a4f8..2cb318dcb17 100644
--- a/addons/web/static/src/js/view_form.js
+++ b/addons/web/static/src/js/view_form.js
@@ -2804,7 +2804,7 @@ instance.web.form.FieldSelection = instance.web.form.AbstractField.extend(instan
var self = this;
this._super(field_manager, node);
this.set("value", false);
- this.set("values", [[false, '']]);
+ this.set("values", []);
this.records_orderer = new instance.web.DropMisordered();
this.field_manager.on("view_content_has_changed", this, function() {
var domain = new openerp.web.CompoundDomain(this.build_domain()).eval();
@@ -2826,14 +2826,9 @@ instance.web.form.FieldSelection = instance.web.form.AbstractField.extend(instan
var model = new openerp.Model(openerp.session, this.field.relation);
def = model.call("search", [this.get("domain")], {"context": this.build_context()}).then(function(record_ids) {
return model.call("name_get", [record_ids] , {"context": self.build_context()});
- }).then(function(res) {
- return [[false, '']].concat(res);
});
} else {
- var values = _(this.field.selection).chain()
- .reject(function (v) { return v[0] === false && v[1] === ''; })
- .unshift([false, ''])
- .value();
+ var values = _.reject(this.field.selection, function (v) { return v[0] === false && v[1] === ''; });
def = $.when(values);
}
this.records_orderer.add(def).then(function(values) {
@@ -2871,8 +2866,8 @@ instance.web.form.FieldSelection = instance.web.form.AbstractField.extend(instan
},
store_dom_value: function () {
if (!this.get('effective_readonly') && this.$('select').length) {
- this.internal_set_value(
- this.get("values")[this.$('select')[0].selectedIndex][0]);
+ var val = JSON.parse(this.$('select').val());
+ this.internal_set_value(val);
}
},
set_value: function(value_) {
@@ -2881,19 +2876,18 @@ instance.web.form.FieldSelection = instance.web.form.AbstractField.extend(instan
this._super(value_);
},
render_value: function() {
+ var values = this.get("values");
+ values = [[false, this.node.attrs.placeholder || '']].concat(values);
+ var found = _.find(values, function(el) { return el[0] === this.get("value"); }, this);
+ if (! found) {
+ found = [this.get("value"), _t('Unknown')];
+ values = [found].concat(values);
+ }
if (! this.get("effective_readonly")) {
- this.$().html(QWeb.render("FieldSelectionSelect", {widget: this}));
- var index = 0;
- _.each(this.get("values"), function(el, i) {
- if (el[0] === this.get('value'))
- index = i;
- }, this);
- this.$el.find('select')[0].selectedIndex = index;
+ this.$().html(QWeb.render("FieldSelectionSelect", {widget: this, values: values}));
+ this.$("select").val(JSON.stringify(found[0]));
} else {
- var self = this;
- var option = _(this.get("values"))
- .detect(function (record) { return record[0] === self.get('value'); });
- this.$el.text(option ? option[1] : this.get("values")[0][1]);
+ this.$el.text(found[1]);
}
},
focus: function() {
diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml
index 513e42bf899..cd96e9648a8 100644
--- a/addons/web/static/src/xml/base.xml
+++ b/addons/web/static/src/xml/base.xml
@@ -1107,10 +1107,9 @@
t-att-tabindex="widget.node.attrs.tabindex"
t-att-autofocus="widget.node.attrs.autofocus"
t-att-id="widget.id_for_label">
- <t t-foreach="widget.get('values')" t-as="option">
- <option>
- <t t-esc="widget.node.attrs.placeholder" t-if="option[0] === false and widget.node.attrs.placeholder"/>
- <t t-esc="option[1]" t-if="option[0] !== false"/>
+ <t t-foreach="values" t-as="option">
+ <option t-att-value="JSON.stringify(option[0])">
+ <t t-esc="option[1]"/>
</option>
</t>
</select>