#automatically toggle switch

19 messages · Page 1 of 1 (latest)

glossy cedarBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

sudden eagle
#

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

fleet talon
#
                            ->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

sudden eagle
#

Looks ok to me

fleet talon
#

yep but its doest work..

sudden eagle
#

you may need to do :

$get('../../directorHoldingCompany')

fleet talon
#

ahhh

#

okay yeppp

#

i had same issuelike 2month ago

#

wait..

#

ahh not works again..

#

like there is 2 active

sudden eagle
#

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

fleet talon
#

mneh its not working btw

sudden eagle
#

provide your whole repeater code