mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-08 06:25:45 +01:00
disable submit button of adding a group if name and description are invalid
This commit is contained in:
@@ -30,7 +30,9 @@
|
|||||||
"label": "Edit"
|
"label": "Edit"
|
||||||
},
|
},
|
||||||
"group-form": {
|
"group-form": {
|
||||||
"submit": "Submit"
|
"submit": "Submit",
|
||||||
|
"name-error": "Group name is invalid",
|
||||||
|
"description-error": "Description is invalid"
|
||||||
},
|
},
|
||||||
"delete-group-button": {
|
"delete-group-button": {
|
||||||
"label": "Delete",
|
"label": "Delete",
|
||||||
|
|||||||
@@ -44,19 +44,25 @@ class GroupForm extends React.Component<Props, State> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onSubmit = (event: Event) => {
|
isFalsy(value) {
|
||||||
event.preventDefault();
|
if (!value) {
|
||||||
this.props.submitForm(this.state.group);
|
return true;
|
||||||
};
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
isValid = () => {
|
isValid = () => {
|
||||||
const group = this.state.group;
|
const group = this.state.group;
|
||||||
return !(this.state.nameValidationError || group.name);
|
return !(
|
||||||
|
this.state.nameValidationError ||
|
||||||
|
this.isFalsy(group.name) ||
|
||||||
|
this.isFalsy(group.description)
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
submit = (event: Event) => {
|
submit = (event: Event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
if (this.isValid) {
|
if (this.isValid()) {
|
||||||
this.props.submitForm(this.state.group);
|
this.props.submitForm(this.state.group);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -69,7 +75,7 @@ class GroupForm extends React.Component<Props, State> {
|
|||||||
nameField = (
|
nameField = (
|
||||||
<InputField
|
<InputField
|
||||||
label={t("group.name")}
|
label={t("group.name")}
|
||||||
errorMessage="group name invalid" // TODO: i18n
|
errorMessage={t("group-form.name-error")}
|
||||||
onChange={this.handleGroupNameChange}
|
onChange={this.handleGroupNameChange}
|
||||||
value={group.name}
|
value={group.name}
|
||||||
validationError={this.state.nameValidationError}
|
validationError={this.state.nameValidationError}
|
||||||
@@ -77,16 +83,16 @@ class GroupForm extends React.Component<Props, State> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<form onSubmit={this.onSubmit}>
|
<form onSubmit={this.submit}>
|
||||||
{nameField}
|
{nameField}
|
||||||
<InputField
|
<InputField
|
||||||
label={t("group.description")}
|
label={t("group.description")}
|
||||||
errorMessage=""
|
errorMessage={t("group-form.description-error")}
|
||||||
onChange={this.handleDescriptionChange}
|
onChange={this.handleDescriptionChange}
|
||||||
value={group.description}
|
value={group.description}
|
||||||
validationError={false}
|
validationError={false}
|
||||||
/>
|
/>
|
||||||
<SubmitButton label={t("group-form.submit")} loading={loading}/>
|
<SubmitButton disabled={!this.isValid()} label={t("group-form.submit")} loading={loading}/>
|
||||||
</form>
|
</form>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user