I'm trying to show repeaters conditionally using checkbox, it works but not as required?
In my filament v3 project, I'm trying to show repeaters conditionally using checkbox which is for the available customers. something like
Section::make('Item Pricing / Linking')->label('Item Pricing / Linking')
->schema([
Checkbox::make('show_all')
->label('Show All')
->live()->afterStateUpdated(function ($state, callable $set) {
if ($state) {
$customers = Customer::all()->toArray();
$set('prices', collect($customers)
->map(fn ($customer) => [
'customer_id' => $customer['id'],
'customer_barcode' => '',
'customer_ref' => '',
'price' => '',
'is_linked' => true, ])->toArray());
} else {
$set('prices', []);
}
}),
Repeater::make('prices')
->relationship('prices')
->schema([
Select::make('customer_id')
->relationship('customer', 'name')
->label('Customer Name'),
TextInput::make('customer_barcode')
->label('Customer Barcode')
->required(),
TextInput::make('customer_ref')
->label('Customer Reference')
->required(),
TextInput::make('price')
->numeric()
->label('Price')
->required(),
Toggle::make('is_linked')
->label('Linked')
->default(true),
])->columns(2)
->live()
->collapsed(false)
->createItemButtonLabel('Add Customer'),
])->columns(1),
it works but not as required. On page load it show blank repeater and when checkbox is checked it shows perfectly as needed. However, when I unchecked this checkbox it hides the whole repeater and I dont want it like that, I want it to be back in the on page load state with one black repeater.
is it possible to achieve? Please help me!0 Replies