Add support for validating more strictly at submit time

When submitting a form, we want to validate more strictly to check for empty
values that might be required. A separate mode is used since we want to ignore
this issue when visiting a field one by one to enter data.

As an example, we convert the pre-existing logic for the username requirement
using this new support.
This commit is contained in:
J. Ryan Stinnett 2019-04-18 21:33:37 +01:00
parent a7c37733b8
commit 1cbb4be6f7
5 changed files with 36 additions and 38 deletions

View file

@ -87,14 +87,15 @@ export default class Field extends React.PureComponent {
this.input.focus();
}
validate({ focused }) {
validate({ focused, allowEmpty = true }) {
if (!this.props.onValidate) {
return;
}
const { value } = this.input;
const value = this.input ? this.input.value : null;
const { valid, feedback } = this.props.onValidate({
value,
focused,
allowEmpty,
});
this.setState({
valid,