diff --git a/lib/fields/input.js b/lib/fields/input.js index a8acd06..904c828 100644 --- a/lib/fields/input.js +++ b/lib/fields/input.js @@ -1,6 +1,7 @@ 'use strict'; var React = require('react'); +var ou = require('../objectUtils'); var $ = React.DOM; var normalizer = require('./utils/normalizer'); @@ -26,10 +27,11 @@ var InputField = React.createClass({ } }, render: function() { + var value = ou.isNil(this.props.value)? '' : this.props.value; return $.input({ type : "text", name : this.props.label, - value : this.props.value || '', + value : value, onKeyPress: this.handleKeyPress, onChange : this.handleChange }); } diff --git a/lib/fields/utils/parser.js b/lib/fields/utils/parser.js index 869176b..f3c07de 100644 --- a/lib/fields/utils/parser.js +++ b/lib/fields/utils/parser.js @@ -1,16 +1,16 @@ 'use strict'; var normalizer = require('./normalizer'); - +var ou = require('../../objectUtils'); exports.string = function(text) { return normalizer.string(text); }; exports.integer = function(text) { - return text ? parseInt(normalizer.integer(text)) : null; + return ou.isNil(text) ? null : parseInt(normalizer.integer(text)); }; exports.number = function(text) { - return text ? parseFloat(normalizer.number(text)) : null; + return ou.isNil(text) ? null : parseFloat(normalizer.number(text)); }; diff --git a/lib/objectUtils.js b/lib/objectUtils.js index 17e444b..be83ab9 100644 --- a/lib/objectUtils.js +++ b/lib/objectUtils.js @@ -24,6 +24,10 @@ var isNat = function(x) { return typeof x == 'number' && x >= 0 && x % 1 == 0; }; +var isNil = function(x) { + return (typeof x === 'undefined' || x === null); +}; + var object = function() { var args = Array.prototype.slice.call(arguments); var result = []; @@ -158,5 +162,6 @@ module.exports = { prune : prune, split : split, map : map, - mapKeys: mapKeys + mapKeys: mapKeys, + isNil : isNil };