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
toeknee3w 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
gigiloouuOP3w 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
toeknee3w ago
Looks ok to me
gigiloouu
gigiloouuOP3w ago
yep but its doest work..
toeknee
toeknee3w ago
you may need to do : $get('../../directorHoldingCompany')
gigiloouu
gigiloouuOP3w ago
ahhh okay yeppp i had same issuelike 2month ago wait.. ahh not works again..
gigiloouu
gigiloouuOP3w ago
No description
gigiloouu
gigiloouuOP3w ago
like there is 2 active
toeknee
toeknee3w 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
gigiloouuOP3w ago
mneh its not working btw
toeknee
toeknee3w ago
provide your whole repeater code
Want results from more Discord servers?
Add your server