Skip to content

Commit c6b8796

Browse files
committed
useRruForm: fix getFieldValue does not return nested fields
1 parent f1917d2 commit c6b8796

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/form/hooks/useRruForm.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import { useState } from 'react';
1818
import { UseFormReturn } from 'react-hook-form';
19-
import { cloneObjectFixingBadArrays } from '../../utils/utils';
19+
import { cloneObjectFixingBadArrays, resolveObjectAttribute } from '../../utils/utils';
2020

2121
export type UseRruFormReturn = {
2222
$: (context: UseFormReturn) => void;
@@ -45,7 +45,7 @@ export const useRruForm = (): UseRruFormReturn => {
4545
};
4646

4747
const getFieldValue = (fieldName: string, preserveArrayKeys?: boolean) => {
48-
return getFieldsValues(preserveArrayKeys)[fieldName];
48+
return resolveObjectAttribute(fieldName, getFieldsValues(preserveArrayKeys));
4949
};
5050

5151
const setFieldValue = (fieldName: string, value: any) => {

stories/Form.RruForm.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ export const NestedFields = (args) => {
256256
console.log('submitting the form', form);
257257
console.log('get preserve default', context.getFieldsValues());
258258
console.log('get preserve true', context.getFieldsValues(true));
259+
console.log('get a single nested field', context.getFieldValue('address.city'));
259260
};
260261

261262
return (

0 commit comments

Comments
 (0)