Skip to content

Commit b9f71fa

Browse files
committed
Remove validation from browser renderer
1 parent 1527d69 commit b9f71fa

File tree

1 file changed

+2
-30
lines changed

1 file changed

+2
-30
lines changed

src/renderer.js

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React from 'react';
22
import ReactDOM from 'react-dom';
33
import EditorState from './editorState';
44
import ReactJSONForm from './form';
5-
import DataValidator from './dataValidation';
65

76

87
export function FormInstance(config) {
@@ -15,7 +14,6 @@ export function FormInstance(config) {
1514
this.fileHandler = config.fileHandler;
1615
this.fieldName = config.fieldName;
1716
this.modelName = config.modelName;
18-
this.validateOnSubmit = config.validateOnSubmit;
1917

2018
this.eventListeners = null;
2119

@@ -40,17 +38,6 @@ export function FormInstance(config) {
4038
};
4139
this.onChange = this.onChange.bind(this);
4240

43-
this.onInvalid = function(e) {
44-
if (!this.eventListeners)
45-
return;
46-
47-
if (!this.eventListeners.hasOwnProperty('invalid') || !this.eventListeners.invalid.size)
48-
return;
49-
50-
this.eventListeners.invalid.forEach((cb) => cb(e));
51-
};
52-
this.onInvalid = this.onInvalid.bind(this);
53-
5441
this.render = function() {
5542
try {
5643
ReactDOM.render(
@@ -63,8 +50,6 @@ export function FormInstance(config) {
6350
fieldName={this.fieldName}
6451
modelName={this.modelName}
6552
onChange={this.onChange}
66-
onInvalid={this.onInvalid}
67-
validateOnSubmit={this.validateOnSubmit}
6853
/>,
6954
document.getElementById(this.containerId)
7055
);
@@ -79,6 +64,7 @@ export function FormInstance(config) {
7964
this.update = function(config) {
8065
this.schema = config.schema || this.schema;
8166
this.data = config.data || this.data;
67+
this.errorMap = config.errorMap || this.errorMap;
8268

8369
this.render();
8470
};
@@ -108,7 +94,6 @@ export class FormContainer extends React.Component {
10894

10995
this.state = {
11096
editorState: EditorState.create(props.schema, props.data),
111-
errorMap: props.errorMap
11297
};
11398

11499
this.prevEditorState = this.state.editorState;
@@ -118,9 +103,6 @@ export class FormContainer extends React.Component {
118103

119104
componentDidMount() {
120105
this.populateDataInput(this.state.editorState.getData());
121-
122-
if (this.props.validateOnSubmit)
123-
this.dataInput.form.addEventListener('submit', this.validateData);
124106
}
125107

126108
componentDidUpdate(prevProps, prevState) {
@@ -158,16 +140,6 @@ export class FormContainer extends React.Component {
158140
this.dataInput.value = JSON.stringify(data);
159141
}
160142

161-
validateData = (e) => {
162-
let validator = new DataValidator(this.state.editorState.getSchema());
163-
let validation = validator.validate(this.state.editorState.getData());
164-
165-
if (!validation.isValid) {
166-
this.props.onInvalid({errorMap: validation.errorMap, submitEvent: e});
167-
this.setState({errorMap: validation.errorMap});
168-
}
169-
}
170-
171143
handleChange = (editorState) => {
172144
this.setState({editorState: editorState});
173145
}
@@ -180,7 +152,7 @@ export class FormContainer extends React.Component {
180152
fileHandler={this.props.fileHandler}
181153
fieldName={this.props.fieldName}
182154
modelName={this.props.modelName}
183-
errorMap={this.state.errorMap}
155+
errorMap={this.props.errorMap}
184156
/>
185157
);
186158
}

0 commit comments

Comments
 (0)