I need to display input types conditionally in both the form and table columns.

If I select 'TextInput' from the 'value_type' dropdown, it will display the TextInput. However, if I choose 'Image,' the FileUpload will appear. By default, both the TextInput and FileUpload are hidden.
public static function form(Form $form): Form
    {
        return $form
            ->schema([
                Section::make()->schema([
                    TextInput::make('name'),
                    Select::make('value_type')
                    ->options([
                        'TextInput' => 'Text Input',
                        'FileUpload' => 'Image'
                    ]),

                    TextInput::make('value'), // If value_type === input
                    FileUpload::make('value') // If value_type === image
                ])
            ]);
    }


It might not be more challenging if TextColumn and ImageColumn are conditionally displayed based on the value type.
public static function table(Table $table): Table
    {
        return $table
            ->columns([
                TextColumn::make('name'),
                TextColumn::make('value'), // If value_type === input
                ImageColumn::make('value'), // If value_type === image
                IconColumn::make('status')
             )]
    }
Was this page helpful?