I'm using Symfony UX Live Components to edit an NtExam. I get this error when editing the form:
Expected argument of type "string", "null" given at property path "exam_title"
. Code Component:
#[AsLiveComponent]
class ExamEditComponent
{
#[LiveProp(writable: true)]
public ?NtExam $ntExam = null;
public bool $showForm = false;
public function __construct(private NtExamRepository $ntExamRepository) {}
public function instantiateForm(): FormInterface
{
$exam = $this->ntExam ?? new NtExam();
return $this->createForm(NtExamType::class, $exam);
}
#[LiveAction]
public function editExam(#[LiveArg] int $id)
{
$this->ntExam = $this->ntExamRepository->find($id);
$this->showForm = true;
}
}
Edit Button
<button class="nt-btn-grey" data-action="live#action" data-live-action-param="editExam"
data-live-id-param="{{ nt_exam.id }}">{{ ux_icon('lucide:file-pen-line',{height :
'16px'}) }}
<span>Edit</span></button>
Form Type (NtExamType):
class NtExamType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder->add('exam_title', TextType::class);
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults(['data_class' => NtExam::class]);
}
}
Template: twig
<div>
{% if component.showForm %}
{{ form_start(form) }}
{{ form_row(form.exam_title) }}
{{ form_end(form) }}
{% endif %}
</div>
Issue The ntExam object has a valid exam_title (confirmed via dd), but form update send null, causing the error.