Dynamic Fields from php

Hello, Been trying to make dynamic fields from values that comes from the php model How am I supposed to be making dynamic fields? Considering this does not "disable" the File one making an error when using type as string?
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Card::make()
->schema([
Forms\Components\Hidden::make('type'), // <---- useless line
Forms\Components\TextInput::make('name')
->required()
->label('Nome')
->maxLength(255),
Forms\Components\FileUpload::make('value')
->label('Arquivo')
->hidden(fn (Config $record) => $record->type !== 'file')
->disabled(fn (Config $record) => $record->type !== 'file'),
Forms\Components\Textarea::make('value')
->label('Value')
->hidden(fn (Config $record) => $record->type !== 'string')
->disabled(fn (Config $record) => $record->type !== 'string'),
])
->columns(2)
]);
}
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Card::make()
->schema([
Forms\Components\Hidden::make('type'), // <---- useless line
Forms\Components\TextInput::make('name')
->required()
->label('Nome')
->maxLength(255),
Forms\Components\FileUpload::make('value')
->label('Arquivo')
->hidden(fn (Config $record) => $record->type !== 'file')
->disabled(fn (Config $record) => $record->type !== 'file'),
Forms\Components\Textarea::make('value')
->label('Value')
->hidden(fn (Config $record) => $record->type !== 'string')
->disabled(fn (Config $record) => $record->type !== 'string'),
])
->columns(2)
]);
}
I don't know if this was supposed to be made with livewire, but I guess it should work already? the hide and disable work fine but really fails to submit
2 Replies
Dan Harrin
Dan Harrin2y ago
the problem is that the file upload needs an array state whereas the textarea doesnt uae that so you need afterStateUpdated() to set the value to be an empty array if the file upload is being used and an empty string if the textarea is used
Picolé
PicoléOP2y ago
thanks for the clarification

Did you find this page helpful?