Skip to content

Commit

Permalink
Handle default value
Browse files Browse the repository at this point in the history
  • Loading branch information
romainseb committed Oct 25, 2023
1 parent 3aad454 commit 936349a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
5 changes: 3 additions & 2 deletions packages/forms/src/rhf/fields/Input/RHFInput.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { useController, useFormContext } from 'react-hook-form';

import Input from '../../../widgets/fields/Input';

function RHFInput(props) {
const { rules = {}, name = '', ...rest } = props;
function RHFInput({ rules = {}, name = '', defaultValue, ...rest }) {
const { control } = useFormContext();
const { field, fieldState } = useController({
control,
name,
rules,
defaultValue,
});
return <Input {...rest} {...field} error={fieldState.error?.message} />;
}
Expand All @@ -18,6 +18,7 @@ if (process.env.NODE_ENV !== 'production') {
RHFInput.propTypes = {
rules: PropTypes.object,
name: PropTypes.string,
defaultValue: PropTypes.string,
};
}

Expand Down
5 changes: 3 additions & 2 deletions packages/forms/src/rhf/fields/Select/RHFSelect.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { useController, useFormContext } from 'react-hook-form';

import Select from '../../../widgets/fields/Select';

function RHFSelect(props) {
const { rules = {}, name = '', ...rest } = props;
function RHFSelect({ rules = {}, name = '', defaultValue, ...rest }) {
const { control } = useFormContext();
const { field, fieldState } = useController({
control,
name,
rules,
defaultValue,
});
return <Select {...rest} {...field} error={fieldState.error?.message} />;
}
Expand All @@ -18,6 +18,7 @@ if (process.env.NODE_ENV !== 'production') {
RHFSelect.propTypes = {
rules: PropTypes.object,
name: PropTypes.string,
defaultValue: PropTypes.string,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { useController, useFormContext } from 'react-hook-form';

import TextArea from '../../../widgets/fields/TextArea';

function RHFTextArea(props) {
const { rules = {}, name = '', ...rest } = props;
function RHFTextArea({ rules = {}, name = '', defaultValue, ...rest }) {
const { control } = useFormContext();
const { field, fieldState } = useController({
control,
name,
rules,
defaultValue,
});

return <TextArea {...rest} {...field} error={fieldState.error?.message} />;
Expand All @@ -19,6 +19,7 @@ if (process.env.NODE_ENV !== 'production') {
RHFTextArea.propTypes = {
rules: PropTypes.object,
name: PropTypes.string,
defaultValue: PropTypes.string,
};
}

Expand Down

0 comments on commit 936349a

Please sign in to comment.