F
Filament5mo ago
Tjiel

Accessing the state of the repeater from inside the repeater

Hey all, I am currently working on a form that has a repeater somewhat like this:
Repeater::make('questions')
->label('Questions')
->translateLabel()
->relationship()
->addActionLabel(__('Add question'))
->collapsed()
->schema([
Forms\Components\TextInput::make('name')
->label('Question')
->translateLabel()
->required()
->maxLength(255),
Select::make('required_question')
->label('Required question')
->translateLabel()
->searchable()
->options(function (Get $get) {
$otherQuestions = $get('questions');
// needs to be questions exluding this one
// logic to return data from questions
})
Repeater::make('questions')
->label('Questions')
->translateLabel()
->relationship()
->addActionLabel(__('Add question'))
->collapsed()
->schema([
Forms\Components\TextInput::make('name')
->label('Question')
->translateLabel()
->required()
->maxLength(255),
Select::make('required_question')
->label('Required question')
->translateLabel()
->searchable()
->options(function (Get $get) {
$otherQuestions = $get('questions');
// needs to be questions exluding this one
// logic to return data from questions
})
In the select called required_question I want to reference a different question from the repeater. I was trying to do this by using $get('questions'). But this results just in a null since its looking for a field called 'questions' in the repeater, which obviously does not exist. So the thing I would like to know is how can i get the values of the other questions as options in my required_question? Any help would be really appreciated, if there are any questions about my problem im happy to provide answers.
2 Replies
Dennis Koch
Dennis Koch5mo ago
It would help reading the code, if you'd remove all the blank spaces. Can you try $get('../questions')?
No description
Tjiel
TjielOP5mo ago
Thanks for suggesting although $get('../questions') did not work $get('../../questions') does, now I only need to find a way to exclude the current question.
Want results from more Discord servers?
Add your server