F
Filamentβ€’17mo ago
Salty

[v2] Using reactive/dependent fields sends all fields to be saved

Having the following configuration
Forms\Components\Section::make('Config')
->schema([
Forms\Components\Fieldset::make('config')
->relationship('config')
->schema([
Forms\Components\Select::make('driver')
->options(DriverOptions::options()->toArray())
->columnSpanFull()
->reactive(),

Forms\Components\Repeater::make('credentials')
->schema([
Forms\Components\TextInput::make('name'),
Forms\Components\TextInput::make('value'),
])
->hidden(function (\Closure $get) {
return $get('driver') !== 'option1';
}),

Forms\Components\Repeater::make('credentials')
->schema([
Forms\Components\TextInput::make('extra_login'),
])
->hidden(function (\Closure $get) {
return $get('driver') !== 'option2';
}),
])
])
Forms\Components\Section::make('Config')
->schema([
Forms\Components\Fieldset::make('config')
->relationship('config')
->schema([
Forms\Components\Select::make('driver')
->options(DriverOptions::options()->toArray())
->columnSpanFull()
->reactive(),

Forms\Components\Repeater::make('credentials')
->schema([
Forms\Components\TextInput::make('name'),
Forms\Components\TextInput::make('value'),
])
->hidden(function (\Closure $get) {
return $get('driver') !== 'option1';
}),

Forms\Components\Repeater::make('credentials')
->schema([
Forms\Components\TextInput::make('extra_login'),
])
->hidden(function (\Closure $get) {
return $get('driver') !== 'option2';
}),
])
])
when I save the model, having selected option1 for instance and filling up the values, I get the extra_login field in my JSON attribute in my model Expected: - name: Name 1 - value: Value 1 Actual - name: Name 1 - value: Value 1 - extra_login: null
1 Reply
Salty
SaltyOPβ€’17mo ago
Any help or tip for a configuration to make the actual object saved ignore the hidden fields? πŸ™
Want results from more Discord servers?
Add your server