I'm using Symfony3 form. I have aCountryType
in my Symfony form Builder. It's working correctly. But suppose the user belongs to a Company which is based in Spain. For that User I want to set the default country to be Spain and then show the rest of the countries. How can I do this in Symfony3.
I tried this but its not working.
$builder->add("country", CountryType::class, array(
"label" => "Country",
"required" => false,
"preferred_choices" => array(
"ES" => "Spain",
),
));
Thank you for your time.
In this type Country::class
, for use the preferred selection on array you should use:
->add('country', CountryType::class, [
'preferred_choices' => ['DE'],
'label' => 'address.form.country.label',
'attr' => [
'class' => 'form-control',
'placeholder' => 'address.form.country.placeholder'
],
'label_attr' => [
'class' => 'col-sm-2 col-form-label'
],
])