retrieve Radio value in custom page.

im currently developing a custom page to answer a quiz. $this->form contains Radio input. when i select an option and save the answer, everything works fine, like showing explanation and right/ wrong icons. however if when i reload the page $this->form is empty. how to set the value for the radio input?
11 Replies
black ka1ser
black ka1ser14mo ago
say this is the link http://127.0.0.1:8000/qpq/quizzes/22/attempt/56 i want to be able to retrieve the option from id question 56
Dan Harrin
Dan Harrin14mo ago
where are you filling the form when the page loads
black ka1ser
black ka1ser14mo ago
by default this is the $form
black ka1ser
black ka1ser14mo ago
this is when i click on save & next (the page does not reload)
black ka1ser
black ka1ser14mo ago
this is when i reload, everything is not there because $this->form has nothing i guess
Dan Harrin
Dan Harrin14mo ago
right but i dont see where you've even attempted to tell Filament where the initial data should come from
black ka1ser
black ka1ser14mo ago
this is my mount method
public function mount($record, $quizQuestion)
{
$this->answered();
// get id from QuizAttempt
$quizAttemptId = QuizAttempt::where([
'quiz_id' => $record,
'participant_id' => Auth::id(),
])->value('id');

// check if question already answered
if (is_null(QuizAttemptAnswer::where([

'quiz_question_id' => $quizQuestion,
'quiz_attempt_id' => $quizAttemptId,

])->value('question_option_id'))) {
// column is empty
$this->formDisabled = false;

$questionId = QuizQuestion::where('id', $quizQuestion)->value('question_id');
$this->questionId = $questionId;

$question = Question::where('id', $questionId)->value('name');

$this->question = $question;
$this->quizQuestion = $quizQuestion;
} else {
// column is not empty/ already has answer
$questionId = QuizQuestion::where('id', $quizQuestion)->value('question_id');
$this->questionId = $questionId;

$question = Question::where('id', $questionId)->value('name');
$this->question = $question;

// retrieve option from $this->form

$this->form->disabled();
}
}
public function mount($record, $quizQuestion)
{
$this->answered();
// get id from QuizAttempt
$quizAttemptId = QuizAttempt::where([
'quiz_id' => $record,
'participant_id' => Auth::id(),
])->value('id');

// check if question already answered
if (is_null(QuizAttemptAnswer::where([

'quiz_question_id' => $quizQuestion,
'quiz_attempt_id' => $quizAttemptId,

])->value('question_option_id'))) {
// column is empty
$this->formDisabled = false;

$questionId = QuizQuestion::where('id', $quizQuestion)->value('question_id');
$this->questionId = $questionId;

$question = Question::where('id', $questionId)->value('name');

$this->question = $question;
$this->quizQuestion = $quizQuestion;
} else {
// column is not empty/ already has answer
$questionId = QuizQuestion::where('id', $quizQuestion)->value('question_id');
$this->questionId = $questionId;

$question = Question::where('id', $questionId)->value('name');
$this->question = $question;

// retrieve option from $this->form

$this->form->disabled();
}
}
Dan Harrin
Dan Harrin14mo ago
you havent called $this->form->fill() with your data?
black ka1ser
black ka1ser14mo ago
inside fill() it can accept for example $something as parameter?
Dan Harrin
Dan Harrin14mo ago
please check the Getting Started docs on the form builder
black ka1ser
black ka1ser14mo ago
thanks found it