Skip to content

Commit

Permalink
Merge pull request #3342 from LiteFarmOrg/LF-4339/product-create-form…
Browse files Browse the repository at this point in the history
…-fix

LF-4339: Create product form validation
  • Loading branch information
kathyavini authored Aug 12, 2024
2 parents f7de2ab + 9301b15 commit 95a315c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ const CreatableSelect = React.forwardRef((props, ref) => {
...restProps
} = props;

const isValidNewOption = (inputValue: string) => {
return inputValue.trim().length > 0;
};

return (
<div data-cy="react-select" className={scss.container} style={style}>
{(label || toolTipContent || icon) && (
Expand All @@ -75,6 +79,7 @@ const CreatableSelect = React.forwardRef((props, ref) => {
isClearable
placeholder={placeholder}
formatCreateLabel={(userInput) => `${createPromptText} "${userInput}"`}
isValidNewOption={isValidNewOption}
styles={{
...(baseStyles as any),
...styles,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,12 @@ const ProductDetails = ({
hookFormRegister={register(SUPPLIER, {
required: interested,
maxLength: hookFormMaxCharsValidation(255),
validate: (value) => {
if (interested && value?.trim().length === 0) {
return t('COMMON_ERRORS.UNIT.REQUIRED');
}
return true;
},
})}
disabled={isDetailDisabled}
hasLeaf={true}
Expand Down

0 comments on commit 95a315c

Please sign in to comment.