Commit e7d27a14 authored by Tomáš Peterka's avatar Tomáš Peterka Committed by Eteri

[renderjs_ui] Generic html5 input is not naive about missing values

Explicitely state which values represent empty values. Coercing to boolean is not sufficient.
parent c270147f
/*global window, rJS, RSVP, jIO */ /*global window, document, rJS, RSVP, jIO */
/*jslint indent: 2, maxerr: 3, maxlen: 80 */ /*jslint indent: 2, maxerr: 3, maxlen: 80 */
(function (window, rJS, RSVP, jIO) { (function (window, document, rJS, RSVP, jIO) {
"use strict"; "use strict";
/** Missing value can have different values based on type.
*
* In general `undefined` and `null` are considered missing values
* Float is missing when `NaN`
*/
function is_missing(value) {
if (value === undefined || value === null) {return true; }
if (typeof value === "number") {return window.isNaN(value); }
return false;
}
rJS(window) rJS(window)
.setState({ .setState({
editable: false, editable: false,
value: undefined, value: undefined,
checked: undefined, checked: undefined,
hidden: false,
title: '', title: '',
name: '', name: '',
type: 'text', type: 'text',
...@@ -19,22 +31,22 @@ ...@@ -19,22 +31,22 @@
}) })
.declareMethod('render', function (options) { .declareMethod('render', function (options) {
var state_dict = { return this.changeState({
value: options.value || "", // display nothing for missing values
checked: options.checked, value: is_missing(options.value) ? "" : options.value,
editable: options.editable, checked: options.checked,
required: options.required, editable: options.editable,
name: options.name, required: options.required,
type: options.type || 'text', name: options.name,
title: options.title, type: options.type || 'text',
focus: options.focus, title: options.title,
step: options.step, focus: options.focus,
hidden: options.hidden, step: options.step,
trim: options.trim || false, hidden: options.hidden,
append: options.append, trim: options.trim || false,
prepend: options.prepend append: options.append,
}; prepend: options.prepend
return this.changeState(state_dict); });
}) })
.onStateChange(function (modification_dict) { .onStateChange(function (modification_dict) {
...@@ -88,7 +100,7 @@ ...@@ -88,7 +100,7 @@
textarea.autofocus = false; textarea.autofocus = false;
textarea.blur(); textarea.blur();
} }
if (modification_dict.append) { if (modification_dict.append) {
this.element.classList.add('ui-input-has-appendinx'); this.element.classList.add('ui-input-has-appendinx');
tmp = document.createElement('i'); tmp = document.createElement('i');
...@@ -96,7 +108,7 @@ ...@@ -96,7 +108,7 @@
this.element.appendChild(tmp); this.element.appendChild(tmp);
tmp = undefined; tmp = undefined;
} }
if (modification_dict.prepend) { if (modification_dict.prepend) {
this.element.classList.add('ui-input-has-prependinx'); this.element.classList.add('ui-input-has-prependinx');
tmp = document.createElement('i'); tmp = document.createElement('i');
...@@ -199,4 +211,4 @@ ...@@ -199,4 +211,4 @@
return this.notifyInvalid(evt.target.validationMessage); return this.notifyInvalid(evt.target.validationMessage);
}, true, false); }, true, false);
}(window, rJS, RSVP, jIO)); }(window, document, rJS, RSVP, jIO));
\ No newline at end of file \ 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.40519.18664.56814</string> </value> <value> <string>962.13886.9310.48640</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>1503560196.31</float> <float>1505894979.84</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