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