Skip to content

Commit

Permalink
Merge pull request #5812 from FACOLOMBANI/feature/5122-isrequired-option
Browse files Browse the repository at this point in the history
added possibility to pass isRequired as option to useInput hook
  • Loading branch information
djhi committed Feb 11, 2021
2 parents 617a4b2 + 63789e5 commit 5e4c78e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/ra-core/src/form/useInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface InputProps<T = any>
resource?: string;
source: string;
validate?: Validator | Validator[];
isRequired?: boolean;
}

export interface UseInputValue extends FieldRenderProps<any, HTMLElement> {
Expand All @@ -43,6 +44,7 @@ const useInput = ({
onBlur: customOnBlur,
onChange: customOnChange,
onFocus: customOnFocus,
isRequired: isRequiredOption,
...options
}: InputProps): UseInputValue => {
const finalName = name || source;
Expand Down Expand Up @@ -112,7 +114,7 @@ const useInput = ({
id: id || source,
input: options.input,
meta: options.meta,
isRequired: isRequired(validate),
isRequired: isRequiredOption || isRequired(validate),
};
}

Expand All @@ -125,7 +127,7 @@ const useInput = ({
onFocus: handleFocus,
},
meta,
isRequired: isRequired(validate),
isRequired: isRequiredOption || isRequired(validate),
};
};

Expand Down

0 comments on commit 5e4c78e

Please sign in to comment.