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

Commit 55d5aae

Browse files
committed
Merge branch 'issue-9'
2 parents 858734b + 3b56f34 commit 55d5aae

File tree

6 files changed

+47
-11
lines changed

6 files changed

+47
-11
lines changed

example/src/body/Example.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ class Example extends React.Component<any, any> {
3030
},
3131
};
3232

33+
componentDidCatch() {
34+
this.setState({
35+
[this.state.backType]: this.state.backSource,
36+
});
37+
}
38+
3339
componentWillReceiveProps = ({ data }) => {
3440
this.setState({
3541
...data,
@@ -39,6 +45,8 @@ class Example extends React.Component<any, any> {
3945
onChange = type => value => {
4046
this.setState({
4147
[type]: value,
48+
backSource: this.state[type],
49+
backType: type,
4250
});
4351
};
4452

@@ -64,7 +72,7 @@ class Example extends React.Component<any, any> {
6472
render() {
6573
const { data, classes } = this.props;
6674
const { title } = data;
67-
const { schema, uiSchema, formData, liveSettings } = this.state;
75+
const { schema, uiSchema, formData, liveSettings, validate } = this.state;
6876

6977
return (
7078
<Paper className={classes.root}>
@@ -114,6 +122,7 @@ class Example extends React.Component<any, any> {
114122
onChange={this.onFormChanged}
115123
liveValidate={liveSettings.validate}
116124
disabled={liveSettings.disabled}
125+
validate={validate}
117126
>
118127
<Box mt={2}>
119128
<Button

example/src/body/Source.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,25 @@ import { Controlled as CodeMirror } from 'react-codemirror2';
66
import 'codemirror/lib/codemirror.css';
77
import 'codemirror/theme/material.css';
88
import 'codemirror/mode/javascript/javascript';
9-
// eslint-disable-line
9+
1010
import Valid from '@material-ui/icons/CheckCircle';
1111
import Invalid from '@material-ui/icons/HighlightOff';
1212
import { withStyles } from '@material-ui/core/styles';
1313

1414
import sourceStyles from './editor-styles';
1515

1616
const cmOptions = {
17-
// mode: { name: 'javascript', json: true },
18-
// theme: 'material',
19-
smartIndent: true,
17+
readOnly: false,
18+
viewportMargin: Infinity,
19+
mode: {
20+
name: 'javascript',
21+
json: true,
22+
statementIndent: 2,
23+
},
2024
lineNumbers: true,
2125
lineWrapping: true,
22-
readOnly: false,
26+
indentWithTabs: false,
27+
tabSize: 2,
2328
};
2429

2530
const isValid = value => {
@@ -62,6 +67,7 @@ class Source extends React.Component<any, any> {
6267
valid: parsed,
6368
source: value,
6469
});
70+
6571
if (parsed && onChange) {
6672
onChange(parsed);
6773
}
@@ -71,6 +77,7 @@ class Source extends React.Component<any, any> {
7177
const { source, valid } = this.state;
7278
const { classes, title } = this.props;
7379
const Icon = valid ? Valid : Invalid;
80+
7481
return (
7582
<div className={classes.root}>
7683
<div className={classNames(classes.ctr, { [classes.invalid]: !valid })}>
@@ -85,6 +92,7 @@ class Source extends React.Component<any, any> {
8592
value={source}
8693
onChange={this.onChange}
8794
onBeforeChange={this.onBeforeChange}
95+
autoCursor={true}
8896
options={cmOptions}
8997
/>
9098
</div>
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import schema from './schema.json';
22
import uiSchema from './ui-schema.json';
33
import formData from './form-data.json';
4+
import validate from './validate';
45

5-
export default ({
6+
export default {
67
title: 'Validation',
78
schema,
89
uiSchema,
910
formData,
10-
});
11+
validate,
12+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { FormValidation } from 'react-jsonschema-form';
2+
3+
const validate = ({ pass1, pass2 }: any, errors: FormValidation) => {
4+
if (pass1 !== pass2) {
5+
errors.pass2.addError("Passwords don't match.");
6+
}
7+
8+
return errors;
9+
};
10+
11+
export default validate;

example/src/menu/Menu.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class RawMenuAppBar extends React.Component<any, any> {
2525
render() {
2626
const { classes, onSelectMenuItem } = this.props;
2727
const { drawerOpen } = this.state;
28+
2829
return (
2930
<AppBar position="static" className={classes.toolbar}>
3031
<Toolbar>

src/Theme/Theme.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@ import FieldTemplate from '../FieldTemplate';
55
import ObjectFieldTemplate from '../ObjectFieldTemplate';
66
import Widgets from '../Widgets';
77

8-
const Theme = {
8+
import { ThemeProps } from 'react-jsonschema-form';
9+
import { getDefaultRegistry } from 'react-jsonschema-form/lib/utils';
10+
11+
const { fields, widgets } = getDefaultRegistry();
12+
13+
const Theme: ThemeProps = {
914
ArrayFieldTemplate,
10-
fields: Fields,
15+
fields: { ...fields, ...Fields },
1116
FieldTemplate,
1217
ObjectFieldTemplate,
13-
widgets: Widgets,
18+
widgets: { ...widgets, ...Widgets },
1419
ErrorList,
1520
};
1621

0 commit comments

Comments
 (0)