Commit cd410667 authored by Tomáš Peterka's avatar Tomáš Peterka

[renderjs_ui] Form field shows errors even when hidden (user-friendly)

parent 1588c73e
...@@ -84,6 +84,8 @@ ...@@ -84,6 +84,8 @@
}); });
}) })
.declareAcquiredMethod("notifyChange", "notifyChange")
.declareMethod('render', function (options) { .declareMethod('render', function (options) {
var state_dict = { var state_dict = {
label_text: options.field_json.title || '', label_text: options.field_json.title || '',
...@@ -105,7 +107,8 @@ ...@@ -105,7 +107,8 @@
.onStateChange(function (modification_dict) { .onStateChange(function (modification_dict) {
var gadget = this, var gadget = this,
span; span,
promise_queue = new RSVP.Queue();
if (gadget.state.hidden) { if (gadget.state.hidden) {
this.element.hidden = true; this.element.hidden = true;
...@@ -123,16 +126,25 @@ ...@@ -123,16 +126,25 @@
} }
if (modification_dict.hasOwnProperty('error_text')) { if (modification_dict.hasOwnProperty('error_text')) {
// first remove old errors if (this.state.hidden) {
span = this.state.container_element.querySelector('span'); promise_queue.push(function () {
if (span) { return gadget.notifyChange({
this.state.container_element.removeChild(span); "message": gadget.state.error_text,
} "status": "error"
// display new error if present });
if (this.state.error_text) { });
span = document.createElement('span'); } else {
span.textContent = this.state.error_text; // first remove old errors
this.state.container_element.appendChild(span); span = this.state.container_element.querySelector('span');
if (span) {
this.state.container_element.removeChild(span);
}
// display new error if present
if (this.state.error_text) {
span = document.createElement('span');
span.textContent = this.state.error_text;
this.state.container_element.appendChild(span);
}
} }
} }
...@@ -147,7 +159,7 @@ ...@@ -147,7 +159,7 @@
if (modification_dict.hasOwnProperty('options')) { if (modification_dict.hasOwnProperty('options')) {
if (this.state.field_url) { if (this.state.field_url) {
return new RSVP.Queue() return promise_queue
.push(function () { .push(function () {
if (modification_dict.hasOwnProperty('field_url')) { if (modification_dict.hasOwnProperty('field_url')) {
return gadget.declareGadget(gadget.state.field_url, { return gadget.declareGadget(gadget.state.field_url, {
...@@ -177,6 +189,7 @@ ...@@ -177,6 +189,7 @@
if (gadget.checkValidity !== undefined) { if (gadget.checkValidity !== undefined) {
return gadget.checkValidity(); return gadget.checkValidity();
} }
window.console.log('Gadget ' + gadget.state.field_url + ' does NOT implement checkValidity!');
return true; return true;
}); });
}) })
......
...@@ -230,7 +230,7 @@ ...@@ -230,7 +230,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>961.46539.43459.6519</string> </value> <value> <string>962.34466.32248.6604</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>1503932157.58</float> <float>1507042725.04</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -69,6 +69,11 @@ ...@@ -69,6 +69,11 @@
} }
data[this.state.name] = this.state.text_content || this.state.inner_html || ""; data[this.state.name] = this.state.text_content || this.state.inner_html || "";
return data; return data;
})
/** Readonly fields are always valid */
.declareMethod("checkValidity", function () {
return true;
}); });
}(window, document, rJS)); }(window, document, rJS));
\ No newline at end of file
...@@ -230,7 +230,7 @@ ...@@ -230,7 +230,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>961.46335.40182.23005</string> </value> <value> <string>961.57904.26336.47172</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>1503909097.14</float> <float>1504605935.05</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