Setting Values in a repeater

Assume that I have a text field named maximum_quantity and a repeater with 2 fields each like this ['repeater' => ['quantity_per_year', 'title']] How do I set the maximum_quantity value inside the repeater quantity_per_year?
6 Replies
RickDB
RickDB16mo ago
Hi @captainjoker:
->afterStateUpdated(function () use ($get, $set) {
$set('repeaterfield', [
['quantity_per_year' => $get('maximum_quantity)],
['quantity_per_year' => $get('maximum_quantity)]
])
->afterStateUpdated(function () use ($get, $set) {
$set('repeaterfield', [
['quantity_per_year' => $get('maximum_quantity)],
['quantity_per_year' => $get('maximum_quantity)]
])
Sorry for formatting, but try somethung like this It's just an array!
CaptainJoker
CaptainJokerOP16mo ago
Hello @rickdb The repeater is dynamic in nature, this works if there are 2 but not less or more than 2 How do we change that?
RickDB
RickDB16mo ago
Tbh, is setting a default value sufficient? because then you can also just use
->default(fn (callable $get) => $get('maximum'))
->default(fn (callable $get) => $get('maximum'))
CaptainJoker
CaptainJokerOP16mo ago
I do not think so
toeknee
toeknee16mo ago
Build a loop, and count the quanities and remove that from the available quanity = max quanity
CaptainJoker
CaptainJokerOP16mo ago
I have done it like this foreach ($get('repeater') as $repeater){ $set($repeater['quantity_per_year'], $quantity_per_year); } but it is not setting the value
Want results from more Discord servers?
Add your server