Commit a64d97cb authored by Romain Courteaud's avatar Romain Courteaud

[erp5_web_renderjs_ui] stringfield.render now support being called multiple times

parent e3eb3402
...@@ -20,26 +20,38 @@ ...@@ -20,26 +20,38 @@
}) })
.declareMethod('render', function (options) { .declareMethod('render', function (options) {
var element, var element,
text, field_json = options.field_json || {},
field_json = options.field_json || {}; created = false;
this.props.value = field_json.value || field_json.default || ""; this.props.value = field_json.value || field_json.default || "";
this.props.editable = field_json.editable; this.props.editable = field_json.editable;
if (field_json.editable) { if (field_json.editable) {
element = this.element.querySelector('input');
if (element === null) {
element = document.createElement('input'); element = document.createElement('input');
element.setAttribute("type", "text"); element.setAttribute("type", "text");
created = true;
}
element.setAttribute('value', this.props.value); element.setAttribute('value', this.props.value);
element.setAttribute('name', field_json.key); element.setAttribute('name', field_json.key);
element.setAttribute('title', field_json.title); element.setAttribute('title', field_json.title);
if (field_json.required === 1) { if (field_json.required === 1) {
element.setAttribute('required', 'required'); element.setAttribute('required', 'required');
} else {
element.removeAttribute('required');
} }
} else { } else {
element = this.element.querySelector('p');
if (element === null) {
element = document.createElement("p"); element = document.createElement("p");
element.setAttribute("class", "ui-content-non-editable"); element.setAttribute("class", "ui-content-non-editable");
text = document.createTextNode(this.props.value); created = true;
element.appendChild(text);
} }
element.textContent = this.props.value;
}
if (created) {
this.element.innerHTML = '';
this.element.appendChild(element); this.element.appendChild(element);
}
}) })
.declareMethod('getContent', function () { .declareMethod('getContent', function () {
......
...@@ -230,7 +230,7 @@ ...@@ -230,7 +230,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>949.22535.16679.23876</string> </value> <value> <string>953.628.51543.17476</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -248,7 +248,7 @@ ...@@ -248,7 +248,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1456317346.39</float> <float>1470314253.13</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment