Filtering ENUMS in option list
i have this options list
i want to hide 2 options if the $record->parts is null
this is my enum
i want to hide REGULAR and AGGREGATE
->form([
Forms\Components\Radio::make('type')
->label('Type')
->default('regular')
->options(PrintOptions::class)
])
->form([
Forms\Components\Radio::make('type')
->label('Type')
->default('regular')
->options(PrintOptions::class)
])
enum PrintOptions: string implements HasLabel
{
case REGULAR = 'regular';
case AGGREGATE = 'aggregate';
case LABEL = 'label';
case RECEIPT = 'receipt';
case DATAAUTH = 'authorization';
public function getLabel(): ?string
{
return match ($this) {
self::REGULAR => 'regular',
self::AGGREGATE => 'aggregate',
self::LABEL => 'label',
self::RECEIPT => 'receipt',
self::DATAAUTH => 'Data authorization',
};
}
}
enum PrintOptions: string implements HasLabel
{
case REGULAR = 'regular';
case AGGREGATE = 'aggregate';
case LABEL = 'label';
case RECEIPT = 'receipt';
case DATAAUTH = 'authorization';
public function getLabel(): ?string
{
return match ($this) {
self::REGULAR => 'regular',
self::AGGREGATE => 'aggregate',
self::LABEL => 'label',
self::RECEIPT => 'receipt',
self::DATAAUTH => 'Data authorization',
};
}
}
2 Replies
array_filter ?
found this
it works with one option, now i have to find the right sintax for two options but it work
et voilà
sorry, this one
->disableOptionWhen(function (string $value, Model $record) {
return $value === 'aggregate' && $record->parts === null;
})
->disableOptionWhen(function (string $value, Model $record) {
return $value === 'aggregate' && $record->parts === null;
})
->disableOptionWhen(function (string $value, Model $record) {
return $value === 'aggregate' || $value === 'regular' && $record->parts === null;
})
->disableOptionWhen(function (string $value, Model $record) {
return $value === 'aggregate' || $value === 'regular' && $record->parts === null;
})
->disableOptionWhen(function (string $value, Model $record) {
return $value === 'aggregate' && $record->parts === null || $value === 'regular' && $record->parts === null;
})
->disableOptionWhen(function (string $value, Model $record) {
return $value === 'aggregate' && $record->parts === null || $value === 'regular' && $record->parts === null;
})