Skip to content
This repository was archived by the owner on Feb 29, 2024. It is now read-only.

Commit ace5646

Browse files
committed
out validstate to onSubmit, touching all inputs on Submit
1 parent 82d4906 commit ace5646

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/Form.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,16 @@ export default class Form extends React.Component {
4646
onSubmit(event) {
4747
event.preventDefault();
4848

49+
for (let input of this.inputs) {
50+
input.touch();
51+
}
52+
53+
const valid = this.isValid();
4954
if (this.props.onSubmit) {
50-
this.props.onSubmit(this.getValues());
55+
this.props.onSubmit(this.getValues(), valid);
5156
}
5257

53-
if (this.isValid()) {
58+
if (valid) {
5459
this.onValidSubmit();
5560
} else {
5661
this.onInvalidSubmit();

src/Input.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export default function (WrappedComponent) {
9898
return this.state.errors;
9999
}
100100

101-
onBlur() {
101+
touch() {
102102
if (this.isPristine()) {
103103
this.setState({
104104
pristine: false
@@ -160,7 +160,7 @@ export default function (WrappedComponent) {
160160
getValue: this.getValue,
161161
setValue: this.setValue,
162162
getErrorMessages: this.getErrorMessages,
163-
onBlur: this.onBlur,
163+
onBlur: this.touch,
164164
...this.props
165165
};
166166

0 commit comments

Comments
 (0)