#automatically toggle switch
19 messages · Page 1 of 1 (latest)
You will need to after so after the state has updated on that toggle, to then get the repeater array and set = flase where the Select is not = to the select in this groiup so
->label('აქტიური დირექტორი')
->default(false)
->afterStateUpdated(function ($state, $get) {
if ($state) {
foreach ($get('directorHoldingCompany') as &$director) {
if ($director['is_active'] && $director['id'] !== $get('id')) {
$director['is_active'] = false;
}
}
}
}),```
there is my code btw
Looks ok to me
yep but its doest work..
you may need to do :
$get('../../directorHoldingCompany')
ahhh
okay yeppp
i had same issuelike 2month ago
wait..
ahh not works again..
like there is 2 active
dd on the getter
just realised you are not re-setting the field, one second.
Forms\Components\Toggle::make('is_active')
->label('აქტიური დირექტორი')
->default(false)
->afterStateUpdated(function ($state, $get, $set) {
if ($state) {
$directors = $get('../../directorHoldingCompany');
foreach ($directors as &$director) {
if ($director['is_active'] && $director['id'] !== $get('id')) {
$director['is_active'] = false;
}
}
$set('../../directorHoldingCompany', $directors);
}
}),
Something like that
mneh its not working btw
provide your whole repeater code