FilamentF
Filament2y ago
CGM

How do I test MorphToSelect fields in forms?

I'm trying to write a test to ensure my MorphToSelect field is ->required(), but it is not behaving as I would expect. Are you all aware of any examples of testing the MorphToSelect field in custom forms, or even in panel forms?

Here is the field for reference:

Here is the example field for reference:

MorphToSelect::make('followup')
   ->required()
   ->types([
      MorphToSelect\Type::make(CustomMessage::class)
         ->getOptionLabelFromRecordUsing(fn (CustomMessage $record): string => "{$record->name}")
         ->titleAttribute('name'),
      MorphToSelect\Type::make(Redirect::class)
         ->getOptionLabelFromRecordUsing(fn (Redirect $record): string => "{$record->name}")
         ->titleAttribute('name'),
])
Was this page helpful?