Commit 10f9b012 authored by Tomáš Peterka's avatar Tomáš Peterka Committed by Tomáš Peterka

[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 819f77ec
/*global window, rJS, RSVP, jIO */
/*global window, document, rJS, RSVP, jIO */
/*jslint indent: 2, maxerr: 3, maxlen: 80 */
(function (window, rJS, RSVP, jIO) {
(function (window, document, rJS, RSVP, jIO) {
"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)
.setState({
editable: false,
value: undefined,
checked: undefined,
hidden: false,
title: '',
name: '',
type: 'text',
......@@ -19,8 +31,9 @@
})
.declareMethod('render', function (options) {
var state_dict = {
value: options.value || "",
return this.changeState({
// display nothing for missing values
value: is_missing(options.value) ? "" : options.value,
checked: options.checked,
editable: options.editable,
required: options.required,
......@@ -33,8 +46,7 @@
trim: options.trim || false,
append: options.append,
prepend: options.prepend
};
return this.changeState(state_dict);
});
})
.onStateChange(function (modification_dict) {
......@@ -199,4 +211,4 @@
return this.notifyInvalid(evt.target.validationMessage);
}, true, false);
}(window, rJS, RSVP, jIO));
\ No newline at end of file
}(window, document, rJS, RSVP, jIO));
\ No newline at end of file
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>961.40519.18664.56814</string> </value>
<value> <string>962.13886.9310.48640</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1503560196.31</float>
<float>1505894979.84</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