Skip to content

Commit ed1c874

Browse files
authored
fix(plugin-ecommerce): priceInput does not respect required field status (#15783)
### What? The `PriceInput` component in `@payloadcms/plugin-ecommerce` does not show the required indicator (asterisk) on the field label when the field is configured with `required: true`. ### Why? `PriceInput` receives the full `field` object (which includes `required`), but never passes it down to `FormattedInput`. `FormattedInput` in turn doesn't accept or forward a `required` prop to `FieldLabel`. ### How? - Pass `field.required` from `PriceInput` to `FormattedInput` - Add `required` to the `FormattedInput` props interface - Forward `required` to the `FieldLabel` component
1 parent 2b23010 commit ed1c874

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

packages/plugin-ecommerce/src/ui/PriceInput/FormattedInput.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ interface Props {
2020
path: string
2121
placeholder?: string
2222
readOnly?: boolean
23+
required?: boolean
2324
supportedCurrencies: Currency[]
2425
}
2526

@@ -34,6 +35,7 @@ export const FormattedInput: React.FC<Props> = ({
3435
path,
3536
placeholder = '0.00',
3637
readOnly,
38+
required,
3739
supportedCurrencies,
3840
}) => {
3941
const { setValue, value } = useField<number>({ path })
@@ -136,7 +138,7 @@ export const FormattedInput: React.FC<Props> = ({
136138

137139
return (
138140
<div className={`field-type number ${baseClass}`}>
139-
{label && <FieldLabel as="label" htmlFor={id} label={label} />}
141+
{label && <FieldLabel as="label" htmlFor={id} label={label} required={required} />}
140142

141143
<div className={`${baseClass}Container`}>
142144
<div className={`${baseClass}CurrencySymbol`}>

packages/plugin-ecommerce/src/ui/PriceInput/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export const PriceInput: React.FC<Props> = (args) => {
3838
label={label}
3939
path={path}
4040
readOnly={readOnly}
41+
required={field.required}
4142
supportedCurrencies={currenciesConfig?.supportedCurrencies}
4243
/>
4344
)

0 commit comments

Comments
 (0)