Wizard: Reset error text and validate on plus button
This updates `<ChippingInput>` component to resolve two bugs: - validation wasn't triggered when using the plus button on Timezone and Locale steps - error text wasn't reset when the value was changed or cleared
This commit is contained in:
parent
adf802174c
commit
db52b869b5
1 changed files with 24 additions and 16 deletions
|
|
@ -44,31 +44,39 @@ const ChippingInput = ({
|
|||
value: string
|
||||
) => {
|
||||
setInputValue(value);
|
||||
setErrorText('');
|
||||
};
|
||||
|
||||
const addItem = (value: string) => {
|
||||
if (validator(value) && !list?.includes(value)) {
|
||||
dispatch(addAction(value));
|
||||
setInputValue('');
|
||||
setErrorText('');
|
||||
}
|
||||
|
||||
if (list?.includes(value)) {
|
||||
setErrorText(`${item} already exists.`);
|
||||
}
|
||||
|
||||
if (!validator(value)) {
|
||||
setErrorText('Invalid format.');
|
||||
}
|
||||
};
|
||||
|
||||
const handleKeyDown = (e: React.KeyboardEvent, value: string) => {
|
||||
if (e.key === ' ' || e.key === 'Enter' || e.key === ',') {
|
||||
e.preventDefault();
|
||||
|
||||
if (validator(value) && !list?.includes(value)) {
|
||||
dispatch(addAction(value));
|
||||
setInputValue('');
|
||||
setErrorText('');
|
||||
}
|
||||
|
||||
if (list?.includes(value)) {
|
||||
setErrorText(`${item} already exists.`);
|
||||
}
|
||||
|
||||
if (!validator(value)) {
|
||||
setErrorText('Invalid format.');
|
||||
}
|
||||
addItem(value);
|
||||
}
|
||||
};
|
||||
|
||||
const handleAddItem = (e: React.MouseEvent, value: string) => {
|
||||
dispatch(addAction(value));
|
||||
addItem(value);
|
||||
};
|
||||
|
||||
const handleClear = () => {
|
||||
setInputValue('');
|
||||
setErrorText('');
|
||||
};
|
||||
|
||||
return (
|
||||
|
|
@ -91,7 +99,7 @@ const ChippingInput = ({
|
|||
</Button>
|
||||
<Button
|
||||
variant="plain"
|
||||
onClick={() => setInputValue('')}
|
||||
onClick={handleClear}
|
||||
isDisabled={!inputValue}
|
||||
aria-label="Clear input"
|
||||
>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue