mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 00:15:44 +01:00
add ui validation
This commit is contained in:
@@ -10,7 +10,8 @@ type Props = {
|
|||||||
buttonLabel: string,
|
buttonLabel: string,
|
||||||
fieldLabel: string,
|
fieldLabel: string,
|
||||||
errorMessage: string,
|
errorMessage: string,
|
||||||
helpText?: string
|
helpText?: string,
|
||||||
|
validateEntry?: string => boolean
|
||||||
};
|
};
|
||||||
|
|
||||||
type State = {
|
type State = {
|
||||||
@@ -25,6 +26,15 @@ class AddEntryToTableField extends React.Component<Props, State> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isValid = () => {
|
||||||
|
const {validateEntry} = this.props;
|
||||||
|
if (!this.state.entryToAdd || this.state.entryToAdd === "" || !validateEntry) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return validateEntry(this.state.entryToAdd);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {
|
const {
|
||||||
disabled,
|
disabled,
|
||||||
@@ -39,7 +49,7 @@ class AddEntryToTableField extends React.Component<Props, State> {
|
|||||||
label={fieldLabel}
|
label={fieldLabel}
|
||||||
errorMessage={errorMessage}
|
errorMessage={errorMessage}
|
||||||
onChange={this.handleAddEntryChange}
|
onChange={this.handleAddEntryChange}
|
||||||
validationError={false}
|
validationError={!this.isValid()}
|
||||||
value={this.state.entryToAdd}
|
value={this.state.entryToAdd}
|
||||||
onReturnPressed={this.appendEntry}
|
onReturnPressed={this.appendEntry}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
@@ -48,7 +58,7 @@ class AddEntryToTableField extends React.Component<Props, State> {
|
|||||||
<AddButton
|
<AddButton
|
||||||
label={buttonLabel}
|
label={buttonLabel}
|
||||||
action={this.addButtonClicked}
|
action={this.addButtonClicked}
|
||||||
disabled={disabled || this.state.entryToAdd ===""}
|
disabled={disabled || this.state.entryToAdd ==="" || !this.isValid()}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user