F
Filament14mo ago
Askancy

How can I add a condition in a form?

I have this code in my form:
return $form
->schema([
Section::make()
->schema([
Repeater::make('trofei')
->createItemButtonLabel('Add Achiviements')
->relationship('trofei')
->schema([
TextInput::make('nome'),
TextInput::make('descrizione'),
Select::make('valore')
->label('Piattaforme:')
->options([
'1' => 'Bronzo',
'2' => 'Argento',
'3' => 'Oro',
'4' => 'Platino',
])

])
])
->columns(1)
]);
return $form
->schema([
Section::make()
->schema([
Repeater::make('trofei')
->createItemButtonLabel('Add Achiviements')
->relationship('trofei')
->schema([
TextInput::make('nome'),
TextInput::make('descrizione'),
Select::make('valore')
->label('Piattaforme:')
->options([
'1' => 'Bronzo',
'2' => 'Argento',
'3' => 'Oro',
'4' => 'Platino',
])

])
])
->columns(1)
]);
I would need to do something like this:
if ($record->console_id == '4') {
Select::make('valore')
->label('Piattaforme:')
->options([
'1' => 'Bronzo',
'2' => 'Argento',
'3' => 'Oro',
'4' => 'Platino',
])
} else {
TextInput::make('valore'),
}
if ($record->console_id == '4') {
Select::make('valore')
->label('Piattaforme:')
->options([
'1' => 'Bronzo',
'2' => 'Argento',
'3' => 'Oro',
'4' => 'Platino',
])
} else {
TextInput::make('valore'),
}
2 Replies
Askancy
AskancyOP14mo ago
Thank you! solved with:
Select::make('valore')
->label('valore:')
->options([
'1' => 'Bronzo',
'2' => 'Argento',
'3' => 'Oro',
'4' => 'Platino',
])
->visible(function ($record) {
if($record->id_console == '1' or $record->id_console == '2' or $record->id_console == '30') {
return 'visible';
}
}),
TextInput::make('valore')
->visible(function ($record) {
if($record->id_console == '3' or $record->id_console == '4' or $record->id_console == '29') {
return 'visible';
}
}),
Select::make('valore')
->label('valore:')
->options([
'1' => 'Bronzo',
'2' => 'Argento',
'3' => 'Oro',
'4' => 'Platino',
])
->visible(function ($record) {
if($record->id_console == '1' or $record->id_console == '2' or $record->id_console == '30') {
return 'visible';
}
}),
TextInput::make('valore')
->visible(function ($record) {
if($record->id_console == '3' or $record->id_console == '4' or $record->id_console == '29') {
return 'visible';
}
}),
Want results from more Discord servers?
Add your server