Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Commit

Permalink
Fixed the handling of integer value of zero in input fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
amitsrivastava committed Jan 28, 2016
1 parent ad9132d commit 8fe68c0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
4 changes: 3 additions & 1 deletion lib/fields/input.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var React = require('react');
var ou = require('../objectUtils');
var $ = React.DOM;

var normalizer = require('./utils/normalizer');
Expand All @@ -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 });
}
Expand Down
6 changes: 3 additions & 3 deletions lib/fields/utils/parser.js
Original file line number Diff line number Diff line change
@@ -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));
};
7 changes: 6 additions & 1 deletion lib/objectUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -158,5 +162,6 @@ module.exports = {
prune : prune,
split : split,
map : map,
mapKeys: mapKeys
mapKeys: mapKeys,
isNil : isNil
};

1 comment on commit 8fe68c0

@amitsrivastava
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Integer value of zero is being set to blank in React due to improper handling of these values. I add a function in objectUtils.js though I am not sure if that's the best place to keep it.

Please sign in to comment.