我有兩種形式。對於子表單,我需要刪除所需的選擇性字段。如何從子窗體的字段中刪除所需字段symfony2
CourseType形式:
class CourseType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('contactName', TextType::class, [
'attr' => [
'placeholder' => 'Enter Contact name'
]])
->add('save', SubmitType::class, array('label' => 'Submit'));
}
}
BulkCourseUpdate形式:
class BulkCourseType extends CourseType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
parent::buildForm($builder, $options);
$builder->add('ids', HiddenType::class, array(
'data' => $options['ids'],
'mapped' => false
));
//need to remove required for contactName field
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'ids' => null
]);
}
}
什麼是去除上面的例子中這個屬性最簡單的方法?
in options pass''required'=> false'。 –
如何從'CourseType'爲'contactName'字段的'BulkCourseType'形式傳遞''required'=> false'? 'configureOptions'方法中的 –
。 –