Skip to content

Commit 351ffac

Browse files
committed
Add key to row; Catch error if schema and data mismatch
1 parent e963713 commit 351ffac

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

src/form.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,25 @@ export default class Form extends React.Component {
7575
let data = this.state.data;
7676
let formGroups = [];
7777

78-
if (this.schema.type === 'array') {
79-
return getArrayFormRow(
80-
data, this.schema, 'rjf',
81-
this.handleChange, this.addFieldset, this.removeFieldset,
82-
0
83-
);
84-
} else if (this.schema.type === 'object') {
85-
return getObjectFormRow(
86-
data, this.schema, 'rjf',
87-
this.handleChange, this.addFieldset, this.removeFieldset,
88-
0
78+
try {
79+
if (this.schema.type === 'array') {
80+
return getArrayFormRow(
81+
data, this.schema, 'rjf',
82+
this.handleChange, this.addFieldset, this.removeFieldset,
83+
0
84+
);
85+
} else if (this.schema.type === 'object') {
86+
return getObjectFormRow(
87+
data, this.schema, 'rjf',
88+
this.handleChange, this.addFieldset, this.removeFieldset,
89+
0
90+
);
91+
}
92+
} catch (error) {
93+
formGroups = (
94+
<p style={{color: '#f00'}}>
95+
<strong>(!) Error:</strong> Schema and data do not match.
96+
</p>
8997
);
9098
}
9199

src/ui.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ export function getObjectFormRow(data, schema, name, onChange, onAdd, onRemove,
177177
schema={schema}
178178
addable={schema.additionalProperties}
179179
onAdd={() => handleKeyValueAdd(data, coords, onAdd)}
180+
key={'row_group_' + name}
180181
>
181182
{rows}
182183
</FormGroup>

0 commit comments

Comments
 (0)