Skip to content

Commit

Permalink
Merge branch 'master' into 674-number-handling
Browse files Browse the repository at this point in the history
  • Loading branch information
epicfaace committed Feb 23, 2019
2 parents bd61375 + 07decc5 commit 12cfc74
Show file tree
Hide file tree
Showing 11 changed files with 412 additions and 227 deletions.
219 changes: 0 additions & 219 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"version": "1.2.1",
"description": "A simple React component capable of building HTML forms out of a JSON schema.",
"scripts": {
"build:readme": "toctoc README.md -w",
"build:lib": "rimraf lib && cross-env NODE_ENV=production babel -d lib/ src/",
"build:dist": "rimraf dist && cross-env NODE_ENV=production webpack --config webpack.config.dist.js",
"build:playground": "rimraf build && cross-env NODE_ENV=production webpack --config webpack.config.prod.js && cp playground/index.prod.html build/index.html",
Expand All @@ -14,8 +13,8 @@
"prepare": "npm run dist",
"precommit": "lint-staged",
"publish-to-gh-pages": "npm run build:playground && gh-pages --dist build/",
"publish-to-npm": "npm run build:readme && npm run dist && npm publish",
"preversion": "npm run build:playground && npm run dist && npm run build:readme && npm run cs-check && npm run lint",
"publish-to-npm": "npm run dist && npm publish",
"preversion": "npm run build:playground && npm run dist && npm run cs-check && npm run lint",
"start": "node devServer.js",
"tdd": "cross-env NODE_ENV=test mocha --require babel-register --watch --require ./test/setup-jsdom.js test/**/*_test.js",
"test": "cross-env NODE_ENV=test mocha --require babel-register --require ./test/setup-jsdom.js test/**/*_test.js",
Expand Down Expand Up @@ -96,7 +95,6 @@
"rimraf": "^2.5.4",
"sinon": "^1.17.6",
"style-loader": "^0.13.1",
"toctoc": "^0.2.3",
"webpack": "^4.20.2",
"webpack-cli": "^3.1.2",
"webpack-dev-middleware": "^3.4.0",
Expand Down
13 changes: 12 additions & 1 deletion src/components/fields/MultiSchemaField.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ class AnyOfField extends Component {
augmentedSchema = Object.assign({}, option, requiresAnyOf);
}

// Remove the "required" field as it's likely that not all fields have
// been filled in yet, which will mean that the schema is not valid
delete augmentedSchema.required;

if (isValid(augmentedSchema, formData)) {
return i;
}
Expand All @@ -85,7 +89,14 @@ class AnyOfField extends Component {
const selectedOption = parseInt(event.target.value, 10);
const { formData, onChange, options } = this.props;

if (guessType(formData) === "object") {
const newOption = options[selectedOption];

// If the new option is of type object and the current data is an object,
// discard properties added using the old option.
if (
guessType(formData) === "object" &&
(newOption.type === "object" || newOption.properties)
) {
const newFormData = Object.assign({}, formData);

const optionsToDiscard = options.slice();
Expand Down
2 changes: 1 addition & 1 deletion src/components/fields/ObjectField.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ class ObjectField extends Component {
errorSchema={errorSchema[name]}
idSchema={idSchema[name]}
idPrefix={idPrefix}
formData={formData[name]}
formData={(formData || {})[name]}
onKeyChange={this.onKeyChange(name)}
onChange={this.onPropertyChange(
name,
Expand Down
4 changes: 3 additions & 1 deletion src/components/widgets/SelectWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ function SelectWidget(props) {
const newValue = getValue(event, multiple);
onChange(processValue(schema, newValue));
}}>
{!multiple && !schema.default && <option value="">{placeholder}</option>}
{!multiple && schema.default === undefined && (
<option value="">{placeholder}</option>
)}
{enumOptions.map(({ value, label }, i) => {
const disabled = enumDisabled && enumDisabled.indexOf(value) != -1;
return (
Expand Down
4 changes: 3 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,9 @@ export function toIdSchema(
field,
fieldId,
definitions,
formData[name],
// It's possible that formData is not an object -- this can happen if an
// array item has just been added, but not populated with data yet
(formData || {})[name],
idPrefix
);
}
Expand Down
Loading

0 comments on commit 12cfc74

Please sign in to comment.