prevent for submit with invalid values

This commit is contained in:
Sebastian Sdorra
2018-07-27 10:24:03 +02:00
parent 466d8255eb
commit 70df3e043d

View File

@@ -49,22 +49,30 @@ class UserForm extends React.Component<Props, State> {
this.setState({ user: { ...this.props.user } }); this.setState({ user: { ...this.props.user } });
} }
submit = (event: Event) => { isValid = () => {
event.preventDefault();
this.props.submitForm(this.state.user);
};
render() {
const { t } = this.props;
const user = this.state.user; const user = this.state.user;
const ButtonClickable = return !(
this.state.validatePasswordError || this.state.validatePasswordError ||
this.state.nameValidationError || this.state.nameValidationError ||
this.state.mailValidationError || this.state.mailValidationError ||
this.state.validatePasswordError || this.state.validatePasswordError ||
this.state.displayNameValidationError || this.state.displayNameValidationError ||
user.name === undefined || user.name === undefined ||
user.displayName === undefined; user.displayName === undefined
);
};
submit = (event: Event) => {
event.preventDefault();
if (this.isValid()) {
this.props.submitForm(this.state.user);
}
};
render() {
const { t } = this.props;
const user = this.state.user;
let nameField = null; let nameField = null;
if (!this.props.user) { if (!this.props.user) {
nameField = ( nameField = (
@@ -121,7 +129,7 @@ class UserForm extends React.Component<Props, State> {
checked={user ? user.active : false} checked={user ? user.active : false}
/> />
<SubmitButton <SubmitButton
disabled={ButtonClickable} disabled={!this.isValid()}
label={t("user-form.submit")} label={t("user-form.submit")}
/> />
</form> </form>