Closed tjodalv closed 1 month ago
I think this is a great addition.
I was already looking to this, in order to dynamically set the grid based on some other key.
This allows for doing stuff like this:
TextInput::make('products_number')
->label(__('Number of products'))
->reactive()
->numeric(),
Repeater::make('visible_products')
->reactive()
->schema([
Select::make('product_id')
->label(__('Choose a product'))
->searchable()
->options(fn() => Product::active()->pluck('title', 'id')),
])
->usesPosition()
->hiddenLabel()
->grid(fn(Get $get) => $get('products_number') ?? 4)
Good job @tjodalv and thank you!
Hi, apologies but we are no longer accepting new features for v3 as per #13744. Also, please check out our contributing guide which talks about proposing the feature before submitting the PR, to ensure you aren't spending time building something that we won't merge.
I would accept a PR for this feature when v4 is released, if you are still interested, with the following changes:
auto
at the moment, feels a too bit magic and probably could be accomplished with ->grid(fn (array $state): int => count($state))
. Let's not include that->grid()
multiple times, it will merge onto the array instead of replacing the array, as per the original behaviour that you have removed.Thank you!
Description
The
grid()
method of the Repeater component already accepts arrays, integers, or strings. This PR introduces support for using closures that can be evaluated later. If the value'auto'
is provided to thegrid()
method, a closure will be registered to automatically return the number of items in the Repeater. Additionally, users can provide their own custom closure to calculate the grid size based on specific logic.Functional changes
composer cs
command.