I have a form that consists of text input and select components
And I want to update select component maxItem attribute dynamically based on the text input value.
Is there anyway to do that?
Here’s what I’ve done
FormsComponentsSection::make('Petugas')
->schema([
FormsComponentsTextInput::make('person_num')
->label('Jumlah Petugas')
->required()
->default(0)
->rules(['min:1'])
->live()
->numeric(),
FormsComponentsSelect::make('users')
->label('Petugas')
->relationship('users', 'name')
->maxItems(fn (Get $get): int => $get('person_num'))
->multiple()
->searchable()
->preload()
->required()
->live()
->afterStateUpdated(function (Set $set, Get $get, $state): void {
if (count($state) > $get('person_num')) {
Notification::make()
->title('Jumlah petugas sudah melebihi jumlah yang diinginkan')
->danger()
->send();
}
if (count($state) == $get('person_num')) {
$set('status', 'close');
} else {
$set('status', 'open');
}
}),
])->columns(2),
New contributor
lazycoder is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.