This commit is contained in:
James
2022-08-01 12:23:53 -04:00
parent 663cae4788
commit 408b66590a
2 changed files with 36 additions and 2 deletions

View File

@@ -38,6 +38,7 @@ const useField = <T extends unknown>(options: Options): FieldType<T> => {
const initialValue = field?.initialValue as T; const initialValue = field?.initialValue as T;
const [internalInitialValue, setInternalInitialValue] = useState(() => field?.initialValue as T);
const [internalValue, setInternalValue] = useState(() => field?.value as T); const [internalValue, setInternalValue] = useState(() => field?.value as T);
const [internallyValid, setInternallyValid] = useState<boolean>(undefined); const [internallyValid, setInternallyValid] = useState<boolean>(undefined);
@@ -128,9 +129,13 @@ const useField = <T extends unknown>(options: Options): FieldType<T> => {
]); ]);
useEffect(() => { useEffect(() => {
setInternalValue(initialValue); if (internalInitialValue !== initialValue) {
setInternalValue(initialValue);
setInternalInitialValue(initialValue);
}
setInternallyValid(undefined); setInternallyValid(undefined);
}, [initialValue]); }, [initialValue, internalInitialValue]);
// The only time that the FORM value should be updated // The only time that the FORM value should be updated
// is when the debounced value updates. So, when the debounced value updates, // is when the debounced value updates. So, when the debounced value updates,

View File

@@ -53,6 +53,33 @@ const TabsFields: CollectionConfig = {
}, },
], ],
}, },
{
label: 'Tab with Row',
description: 'This tab has a row field.',
fields: [
{
type: 'row',
fields: [
{
name: 'textInRow',
type: 'text',
required: true,
admin: {
width: '50%',
},
},
{
name: 'numberInRow',
type: 'number',
required: true,
admin: {
width: '50%',
},
},
],
},
],
},
], ],
}, },
{ {
@@ -108,6 +135,8 @@ export const tabsDoc = {
}, },
textarea: 'Here is some text that goes in a textarea', textarea: 'Here is some text that goes in a textarea',
anotherText: 'Super tired of writing this text', anotherText: 'Super tired of writing this text',
textInRow: 'hello',
numberInRow: 235,
}; };
export default TabsFields; export default TabsFields;