I have the following form:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('type', ChoiceType::class, array(
'expanded' => true,
'multiple' => false,
'choices' => array(
'Friend' => 'friend',
'Guide' => 'guide'
)
));
}
How can I make 'Friend' checkbox to be checked by default when the form is rendered ?
If you don't want to override value for an edition you can do this :
Use the
empty_data
form field option. (notdata
because it will override any posted data unless you set it dynamically).Another option for complex cases is to use Sf Dynamic Form Events.
I think it would be better to set initial values in the Entity constructor:
I think you should try with
data
option, but it's just in the case where you don't even have a data saved inside your object, because it will override it else.Important : It's good for create action, but not for edit action.
Official link
Extract :
UPDATE If YOU NEED EMPTY VALUE:
As the answer below, replace
data
withempty_data
if you need in any case to update default value