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 ?
So, we can easily set the default value to people picker control in PowerApps Forms, and we can update person or group field using Patch function. You just must generate the object with specific format which includes Claims, Email, Department, DisplayName, JobTitle and Picture fields. That's it for this article.
At the first entry on the list do a return to create a blank space. Inside that blank space place your cursor and press and hold down the ALT key while typing 0129 on the NUMERIC KEYPAD. ... In the Default Entry setting do the same. Save and you are done.
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.
public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('type', ChoiceType::class, array( 'expanded' => true, 'multiple' => false, 'choices' => array( 'Friend' => 'friend', 'Guide' => 'guide' ), 'data' => 'friend' )); }
Official link
Extract :
When you create a form, each field initially displays the value of the corresponding property of the form's domain object (if an object is bound to the form). If you want to override the initial value for the form or just an individual field, you can set it in the data option
UPDATE If YOU NEED EMPTY VALUE:
As the answer below, replace data
with empty_data
if you need in any case to update default value
Use the empty_data
form field option. (not data
because it will override any posted data unless you set it dynamically).
public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('type', ChoiceType::class, array( 'expanded' => true, 'multiple' => false, 'choices' => array( 'Friend' => 'friend', 'Guide' => 'guide' ), 'empty_data' => 'friend' )); }
Another option for complex cases is to use Sf Dynamic Form Events.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With