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

Handling of integer value of zero #16

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions dist/react-json-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ return /******/ (function(modules) { // webpackBootstrap
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 @@ -391,7 +395,8 @@ return /******/ (function(modules) { // webpackBootstrap
prune : prune,
split : split,
map : map,
mapKeys: mapKeys
mapKeys: mapKeys,
isNil : isNil
};


Expand Down Expand Up @@ -848,6 +853,7 @@ return /******/ (function(modules) { // webpackBootstrap
'use strict';

var React = __webpack_require__(2);
var ou = __webpack_require__(3);
var $ = React.DOM;

var normalizer = __webpack_require__(12);
Expand All @@ -873,10 +879,11 @@ return /******/ (function(modules) { // webpackBootstrap
}
},
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 Expand Up @@ -922,18 +929,18 @@ return /******/ (function(modules) { // webpackBootstrap
'use strict';

var normalizer = __webpack_require__(12);

var ou = __webpack_require__(3);

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));
};


Expand Down Expand Up @@ -1190,7 +1197,6 @@ return /******/ (function(modules) { // webpackBootstrap
'use strict';

var ou = __webpack_require__(3);
var alternative = __webpack_require__(8);

var checkNumber = function(schema, instance) {
var errors = [];
Expand Down Expand Up @@ -1343,9 +1349,6 @@ return /******/ (function(modules) { // webpackBootstrap
if (instance == null)
instance = {};

var alternativeSchema = alternative.schema(instance, schema, context);
schema = alternativeSchema || schema;

if (instance.constructor !== Object)
result.push({ path: [], errors: ['must be a plain object'] });
else {
Expand Down
2 changes: 1 addition & 1 deletion dist/react-json-editor.min.js

Large diffs are not rendered by default.

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
};
4 changes: 0 additions & 4 deletions lib/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ SOFTWARE.
'use strict';

var ou = require('./objectUtils');
var alternative = require('./alternative');

var checkNumber = function(schema, instance) {
var errors = [];
Expand Down Expand Up @@ -174,9 +173,6 @@ validator.object = function(schema, instance, context) {
if (instance == null)
instance = {};

var alternativeSchema = alternative.schema(instance, schema, context);
schema = alternativeSchema || schema;

if (instance.constructor !== Object)
result.push({ path: [], errors: ['must be a plain object'] });
else {
Expand Down