Skip to content

Commit 2ddc626

Browse files
committed
Text input modified to accomodate passing less props.
1 parent b47f3c3 commit 2ddc626

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/App.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class App extends Component {
66
constructor() {
77
super();
88
this.state = {
9+
formIsValid: false, //we will use this to track the overall form validity
910
formControls: {
1011
name: {
1112
value: '',
@@ -37,8 +38,14 @@ class App extends Component {
3738

3839
updatedControls[name] = updatedFormElement;
3940

41+
let formIsValid = true;
42+
for (let inputIdentifier in updatedControls) {
43+
formIsValid = updatedControls[inputIdentifier].valid && formIsValid;
44+
}
45+
4046
this.setState({
41-
formControls: updatedControls
47+
formControls: updatedControls,
48+
formIsValid
4249
});
4350
}
4451

@@ -51,16 +58,17 @@ class App extends Component {
5158
return (
5259
<div className="App">
5360
<h2>Form helper</h2>
54-
<form onSubmit={this.formSubmitHandler}>
55-
<label htmlFor="name">Name{' '}</label>
61+
<form onSubmit={this.formSubmitHandler} autoComplete="off">
5662
<TextInput
57-
id="name"
63+
label="Name"
5864
name="name"
5965
placeholder={this.state.formControls.name.placeholder}
6066
value={this.state.formControls.name.value}
6167
onChange={this.changeHandler}
68+
touched={this.state.formControls.name.touched}
69+
valid={this.state.formControls.name.valid}
6270
/>
63-
<button type="submit"> Submit </button>
71+
<button type="submit" className="btn-submit" disabled={!this.state.formIsValid}> Submit </button>
6472
</form>
6573
</div>
6674
);

0 commit comments

Comments
 (0)