Is it possible to dynamically set ->defaultItems to be the value from another field?

I am toying with this, but I am not even sure if it is valid. ->defaultItems(fn (Closure $get) => $get('../../number_of_documents') != null) Where number_of_documents is a text input of type number outside the repeater
5 Replies
Dan Harrin
Dan Harrin2y ago
default items are only used when the form is first loaded you probably just want an afterStateUpdated() and $set() on the numer_of_documents input
rg.block
rg.blockOP2y ago
Ok, that makes more sense. Trying something like this but I am missing the part that would set defaultItems... ->reactive() ->afterStateUpdated(function (Closure $set, $state) { $set('documents', $state); })
Dan Harrin
Dan Harrin2y ago
$set('documents', array_fill(0, $state ?: 0, [
'field_1' => null,
'field_2' => null,
'field_3' => null,
]))
$set('documents', array_fill(0, $state ?: 0, [
'field_1' => null,
'field_2' => null,
'field_3' => null,
]))
that will create an array of arrays and each item needs a set of blank fields
rg.block
rg.blockOP2y ago
ahh okay, I was thinking of something else... this works great. Thank you. On a separate note, I started sponsoring yesterday in case you can set the discord role. I am hoping to be able to up that as my product gets traction. Thanks again.
Dan Harrin
Dan Harrin2y ago
Thanks, you have the role :)
Want results from more Discord servers?
Add your server