RedSquirrel
Refresh form section description after save
public function form(Form $form): Form
{
$dynamicForm = [];
if($this->question_groups) {
foreach($this->question_groups as $qg) {
$dynamicQuestions = [];
$questions = Question::where('question_group_id', $qg->id)->get();
if($questions) {
$total_answered = 0;
foreach($questions as $q) {
$dynamicQuestions[] = $this->getDynamicField($q);
if($this->checkIfAnswered($q->id, $this->existing_answers)) {
$total_answered = $total_answered + 1;
}
}
}
$total_questions = $questions->count();
$dynamicForm[] = Section::make($qg->name)->collapsed()->description('Completed ' . $total_answered . " of " . $total_questions)->schema($dynamicQuestions);
}
}
return $form
->schema($dynamicForm)
->statePath('data');
}
21 replies
Refresh form section description after save
public function answerform(): void
{
foreach($this->form->getState() as $key => $answer) {
$answers = Answer::where('lead_id', $this->record->id)->where('question_set_id', $this->question_set->id)->where('question_id', $key)->first();
if(!$answers) {
$answers = new Answer;
}
$answers->lead_id = $this->record->id;
$answers->question_set_id = $this->question_set->id;
$answers->question_id = $key;
$answers->value = $answer;
$answers->save();
}
Notification::make()
->title('Updated')
->body('Your answers have been saved')
->success()
->send();
}
21 replies