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
RickDB2y 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
CaptainJokerOP2y 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
RickDB2y 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
CaptainJokerOP2y ago
I do not think so
toeknee
toeknee2y ago
Build a loop, and count the quanities and remove that from the available quanity = max quanity
CaptainJoker
CaptainJokerOP2y 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

Did you find this page helpful?