automatically toggle switch

I want when one toggle is active and if i active another toggle automaticly prev toggle should be go false like i want only one active toggle
No description
11 Replies
toeknee
toeknee2mo ago
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
gigiloouu
gigiloouuOP2mo ago
Forms\Components\Toggle::make('is_active')
->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;
}
}
}
}),
Forms\Components\Toggle::make('is_active')
->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
toeknee
toeknee2mo ago
Looks ok to me
gigiloouu
gigiloouuOP2mo ago
yep but its doest work..
toeknee
toeknee2mo ago
you may need to do : $get('../../directorHoldingCompany')
gigiloouu
gigiloouuOP2mo ago
ahhh okay yeppp i had same issuelike 2month ago wait.. ahh not works again..
gigiloouu
gigiloouuOP2mo ago
No description
gigiloouu
gigiloouuOP2mo ago
like there is 2 active
toeknee
toeknee2mo ago
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);
}
}),
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
gigiloouu
gigiloouuOP2mo ago
mneh its not working btw
toeknee
toeknee2mo ago
provide your whole repeater code
Want results from more Discord servers?
Add your server