F
Filament5mo ago
Daniel

Issue: Reactive Field Visibility Not Working as Expected in ProductPriceResource

I'm having trouble with a reactive form field in ProductPriceResource. A 'Recurring Billing Period' field should show/hide based on a 'Price Type' ToggleButtons selection:
ToggleButtons::make('price_type')
->reactive()
// ... other configurations ...

TextInput::make('recurring_billing_period')
->visible(fn (callable $get) => $get('price_type') === ProductPrice::PRICETYPE_RECURRING)
// ... other configurations ...
ToggleButtons::make('price_type')
->reactive()
// ... other configurations ...

TextInput::make('recurring_billing_period')
->visible(fn (callable $get) => $get('price_type') === ProductPrice::PRICETYPE_RECURRING)
// ... other configurations ...
Problem: The 'Recurring Billing Period' field doesn't appear immediately when 'Recurring' is selected. It only shows up after saving the form. What I've Tried: - Adding ->reactive() to Section and Form - Using afterStateUpdated on 'price_type' - Debug logging This works in other resources (e.g., CourseResource) but not here. Any ideas on what might be causing this and how to fix it?
1 Reply
toeknee
toeknee5mo ago
Strange indeed, hacky but you could try:
->visible(fn (callable $get, $record) => ($get('price_type') === ProductPrice::PRICETYPE_RECURRING) || ($record && $record->price_type === ProductPrice::PRICETYPE_RECURRING))
->visible(fn (callable $get, $record) => ($get('price_type') === ProductPrice::PRICETYPE_RECURRING) || ($record && $record->price_type === ProductPrice::PRICETYPE_RECURRING))
Want results from more Discord servers?
Add your server