Focus the first invalid field

This adjusts the submission step to focus the first invalid field and redisplay
validation. This also rearranges the older style field error handling on
registration which is slated for removal once we convert all fields to the new
style.
This commit is contained in:
J. Ryan Stinnett 2019-04-17 14:23:59 +01:00
parent 62a01e7a37
commit 5d95c31875
2 changed files with 60 additions and 21 deletions

View file

@ -86,6 +86,10 @@ export default class Field extends React.PureComponent {
}
};
focus() {
this.input.focus();
}
validate({ value, focused }) {
if (!this.props.onValidate) {
return;
@ -107,6 +111,7 @@ export default class Field extends React.PureComponent {
// Set some defaults for the <input> element
inputProps.type = inputProps.type || "text";
inputProps.ref = input => this.input = input;
inputProps.placeholder = inputProps.placeholder || inputProps.label;
inputProps.onFocus = this.onFocus;