Skip to content

Commit 8e3e9bf

Browse files
Updated validateAll method to return errors model.
1 parent aa3cc5a commit 8e3e9bf

25 files changed

Lines changed: 6504 additions & 4627 deletions

File tree

README.md

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,17 @@ Object.assign(Validation.rules, {
9898
return password.value === passwordConfirm.value;
9999
},
100100
hint: () => <span className="form-error is-visible">Passwords should be equal.</span>
101+
},
102+
// Define API rule to show hint after API error response
103+
api: {
104+
// We don't need the rule here because we will call the 'showError' method by hand on API error
105+
hint: value => (
106+
<button
107+
className="form-error is-visible"
108+
>
109+
API Error on "{value}" value. Focus to hide.
110+
</button>
111+
)
101112
}
102113
});
103114
```
@@ -165,30 +176,24 @@ Any valid props can easily be passed to ```Form```, such ```onSubmit``` and ```m
165176

166177
3. ```hideError(name)``` - hides a corresponding component's error.
167178

168-
4. ```validateAll()``` - validates all react-validation components. Returns a map (key: field name prop, value: non passed validation rule) of invalid fields. <strong>UPD: from 2.10.0 returns ```undefined```. TBD.</strong>
179+
4. ```validateAll()``` - validates all react-validation components. Returns a map (key: field name prop, value: `<Array>` non passed validation rules) of invalid fields.
169180

170181

171182
```javascript
172183
export default class Comment extends Component {
173-
handleSubmit(event) {
184+
handleSubmit = (event) => {
174185
event.preventDefault();
175186

176187
// Emulate async API call
177188
setTimeout(() => {
178-
this.form.showError('username', value =>
179-
<button
180-
onClick={this.removeApiError.bind(this)}
181-
className="form-error is-visible"
182-
>
183-
API Error on "{value}" value. Click to hide out.
184-
</button>
185-
);
189+
// NOTE: 'api' should be defined on 'extend' step
190+
this.form.showError('username', 'api');
186191
}, 1000);
187-
}
192+
};
188193

189-
removeApiError() {
190-
this.form.hideError("username");
191-
}
194+
removeApiError = () => {
195+
this.form.hideError('username');
196+
};
192197

193198
render() {
194199
return <Validation.components.Form ref={c => { this.form = c }} onSubmit={this.handleSubmit.bind(this)}>
@@ -201,6 +206,7 @@ export default class Comment extends Component {
201206
<div className="small-12 medium-4 columns">
202207
<label>
203208
<Validation.components.Input
209+
onFocus={this.removeApiError}
204210
placeholder="username"
205211
type="text"
206212
errorClassName="is-invalid-input"

0 commit comments

Comments
 (0)