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

Commit 8fe68c0

Browse files
Fixed the handling of integer value of zero in input fields.
1 parent ad9132d commit 8fe68c0

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

lib/fields/input.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
var React = require('react');
4+
var ou = require('../objectUtils');
45
var $ = React.DOM;
56

67
var normalizer = require('./utils/normalizer');
@@ -26,10 +27,11 @@ var InputField = React.createClass({
2627
}
2728
},
2829
render: function() {
30+
var value = ou.isNil(this.props.value)? '' : this.props.value;
2931
return $.input({
3032
type : "text",
3133
name : this.props.label,
32-
value : this.props.value || '',
34+
value : value,
3335
onKeyPress: this.handleKeyPress,
3436
onChange : this.handleChange });
3537
}

lib/fields/utils/parser.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
'use strict';
22

33
var normalizer = require('./normalizer');
4-
4+
var ou = require('../../objectUtils');
55

66
exports.string = function(text) {
77
return normalizer.string(text);
88
};
99

1010
exports.integer = function(text) {
11-
return text ? parseInt(normalizer.integer(text)) : null;
11+
return ou.isNil(text) ? null : parseInt(normalizer.integer(text));
1212
};
1313

1414
exports.number = function(text) {
15-
return text ? parseFloat(normalizer.number(text)) : null;
15+
return ou.isNil(text) ? null : parseFloat(normalizer.number(text));
1616
};

lib/objectUtils.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ var isNat = function(x) {
2424
return typeof x == 'number' && x >= 0 && x % 1 == 0;
2525
};
2626

27+
var isNil = function(x) {
28+
return (typeof x === 'undefined' || x === null);
29+
};
30+
2731
var object = function() {
2832
var args = Array.prototype.slice.call(arguments);
2933
var result = [];
@@ -158,5 +162,6 @@ module.exports = {
158162
prune : prune,
159163
split : split,
160164
map : map,
161-
mapKeys: mapKeys
165+
mapKeys: mapKeys,
166+
isNil : isNil
162167
};

0 commit comments

Comments
 (0)