Skip to content

Commit

Permalink
ISSUE #5143 - fix: names that include a "." do not receive the errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Amantini1997 committed Oct 17, 2024
1 parent ef7849f commit a748e54
Showing 1 changed file with 33 additions and 27 deletions.
60 changes: 33 additions & 27 deletions frontend/src/v5/ui/controls/inputs/inputController.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { forwardRef } from 'react';
import { Controller, ControllerRenderProps } from 'react-hook-form';
import { get } from 'lodash';
import { Controller, ControllerRenderProps, useFormContext } from 'react-hook-form';

export type FormInputProps = Partial<Omit<ControllerRenderProps, 'ref'> & {
required: boolean,
Expand Down Expand Up @@ -52,29 +53,34 @@ export const InputController: InputControllerType = forwardRef(<T,>({
onChange,
onBlur,
...props
}: Props<T>, ref) => (
<Controller
name={name}
control={control}
defaultValue={defaultValue}
render={({ field: { ref: fieldRef, ...field } }) => (
// @ts-ignore
<Input
{...field}
{...props}
value={field.value ?? ''}
onChange={(event) => {
field.onChange(event);
onChange?.(event);
}}
onBlur={() => {
field.onBlur();
onBlur?.();
}}
inputRef={ref || fieldRef}
error={!!formError}
helperText={formError?.message}
/>
)}
/>
));
}: Props<T>, ref) => {
const ctx = useFormContext();
const error = formError || get(ctx?.formState?.errors, name);

return (
<Controller
name={name}
control={control}
defaultValue={defaultValue}
render={({ field: { ref: fieldRef, ...field } }) => (
// @ts-ignore
<Input
{...field}
{...props}
value={field.value ?? ''}
onChange={(event) => {
field.onChange(event);
onChange?.(event);
}}
onBlur={() => {
field.onBlur();
onBlur?.();
}}
inputRef={ref || fieldRef}
error={!!error}
helperText={error?.message}
/>
)}
/>
);
});

0 comments on commit a748e54

Please sign in to comment.