问题
Is there a way to make a A2lix translation field required and validated through the front-end in a Symfony form? I have tried adding a property of presentation
and translations
to my validation.yml
file, but to no avail.
I find that when I don't enter anything in the translation field the form doesn't submit, but nothing happens. No FE or BE error.
My form:
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('translations', 'a2lix_translationsForms', array(
'form_type' => new CourseGuideTranslationType($this->dataClass . 'Translation', $this->validationGroups),
'label' => 'crmpicco.course_guide.name',
'required' => true
))
->add('name', 'text');
}
In validation.yml
:
CRMPicco\GolfBundle\Entity\CourseGuide:
properties:
name:
- NotBlank: ~
CourseGuideTranslationType.php
:
class CourseGuideTranslationType extends AbstractResourceType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('presentation', 'text', array(
'required' => true,
'label' => false,
))
;
}
/**
* {@inheritdoc}
*/
public function getName()
{
return 'crmpicco_course_guide_translation';
}
}
来源:https://stackoverflow.com/questions/33413293/making-a-a2lix-translation-field-required-in-the-front-end-in-a-symfony-form