how can I hide a form field in first repeater
I want one field to be hidden in first item of repeater.
10 Replies
Here's something to experiment with:
https://discord.com/channels/883083792112300104/1147995447332438077/1148629786474844200
@pboivin The second option worked, but if we change the value of another field (let's say toggle or select field) the hidden field get shown again.
Share your code if you can, I'll see if I have any ideas
sure
@pboivin
public function form(Form $form): Form
{
$formSpecificComponents = [
Forms\Components\Grid::make(3)
->schema(
[
Forms\Components\TextInput::make('firstname')
->required()
->label('Firstname')
->required()
->maxLength(255)
->live(),
Forms\Components\TextInput::make('lastname')
->required()
->label('Lastname')
->maxLength(255)
->live(),
Forms\Components\Select::make('country')
->options(Country::all()->pluck('name', 'id'))
->searchable()
->required(),
Forms\Components\Select::make('relationship_with_main')
->label('Relationship with main user')
->options(config('app.relationships'))
->required()
->hidden(function() {
static $row = 0;
return ++$row === 1;
}),
Forms\Components\Toggle::make('primary')
->label('Primary Applicant')
->inline(false)
->disabled()
->dehydrated()
]
),
];
return $form->schema($this->baseFormSchema($formSpecificComponents));
}
--------------------
@pboivin and this component will return to repeater
Repeater::make('applicants')
->relationship()
->schema($repeaterComponents)
->itemLabel('test'),
Is
relationship_with_main
part of the repeater?Yes
@pboivin
Sorry, I don't really understand how your form is setup. What is the content of
$repeaterComponents
?$form->schema($this->baseFormSchema($formSpecificComponents));
You're passing a form into a repeater schema?
Yes