diff --git a/packages/plugin-form-builder/src/collections/Forms/DynamicPriceSelector.tsx b/packages/plugin-form-builder/src/collections/Forms/DynamicPriceSelector.tsx index 7f582b7359a..3ef7baf14a4 100644 --- a/packages/plugin-form-builder/src/collections/Forms/DynamicPriceSelector.tsx +++ b/packages/plugin-form-builder/src/collections/Forms/DynamicPriceSelector.tsx @@ -2,7 +2,7 @@ import type { Data, TextFieldClientComponent } from 'payload' -import { TextField, useLocale, useWatchForm } from '@payloadcms/ui' +import { TextField, useFieldProps, useLocale, useWatchForm } from '@payloadcms/ui' import React, { useEffect, useState } from 'react' type FieldWithID = { @@ -17,13 +17,15 @@ export const DynamicPriceSelector: TextFieldClientComponent = (props) => { const locale = useLocale() + const { path } = useFieldProps() + const [isNumberField, setIsNumberField] = useState() const [valueType, setValueType] = useState<'static' | 'valueOfField'>() // only number fields can use 'valueOfField` useEffect(() => { - if (field?._path) { - const parentPath = field._path.split('.').slice(0, -1).join('.') + if (path) { + const parentPath = path.split('.').slice(0, -1).join('.') const paymentFieldData: any = getDataByPath(parentPath) if (paymentFieldData) { @@ -40,7 +42,7 @@ export const DynamicPriceSelector: TextFieldClientComponent = (props) => { } } } - }, [fields, field._path, getDataByPath, getData]) + }, [fields, getDataByPath, getData, path]) // TODO: make this a number field, block by Payload if (valueType === 'static') {