Reputation: 740
I have 2 forms. For the child form, I need to delete required for selective fields.
CourseType form:
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 form:
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
]);
}
}
What's the easiest way to remove this attribute in the example above?
Upvotes: 1
Views: 4159
Reputation: 740
The easiest way:
$builder->get('contactName')->setRequired(false);
Thanks to all
Upvotes: 4