11.
Form Field Customization
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
Whoops, an error! Please, try again later.
10 Comments
Hi,
I'am trying the use the DateTimeFiled in easyAdmin 3.0.2 bit i'am confused. This is my config for this Field in PostCrudController under configureFields method:
`
DateTimeField::new('publishedAt')
->setFormTypeOption(['widget' => 'single_text'])
->setFormat('dd-MM-yyyy HH:mm')
->setCssClass('datepicker')
`
But I get the following error in the frontend:
Argument 1 passed to EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField::setFormTypeOption() must be of the type string, array given, called in /Users/jonkerh/Sites/my_project/src/Controller/Admin/PostCrudController.php on line 32
Hey @Hans!
Use
setFormTypeOptionswith an "s" at the end :). There IS a method calledsetFormTypeOption(), but it accepts 2 arguments: the option and the value: https://github.com/EasyCorp/EasyAdminBundle/blob/31ff2d884ec6c05c8ddb4186e0eced2b907af8db/src/Field/FieldTrait.php#L95Cheers!
Thanks!!
Hi,
I am trying to add set a value on a form field called user_id this field is required. The form is for creating a new user account. When I loaded up this form I see the user_id value which come from the user object of the logged in user. But, no matter what I seem to try I get a sql error on insert telling me that user_id is null in the values list. How can I accomplish this?
easy_admin.yml config for my UserAccount entity:
`
new:
title: 'Add %%entity_label%%'
fields:
#- '-userid'
`
I also have my own UserAccountController which is where I am trying to set the value for this user_id field in the form previously mentioned.
<br />protected function createNewUserAccountEntity() <br />{ <br />$userAccount = new UserAccount(); <br />$userAccount->setUserId($this->getUser()->getId()); <br />return $userAccount; <br />}<br />In my UserAccount entity my setUserId method looks like this:
`
public function setUserId($id): ?int
{
$this->userid = $id;
return $this->userid;
}
`
Thank you in advance for any help.
Hey Brent
I think you should set the userId in the
preFlushaction. I believe there is something in the middle of EasyAdmin workflow that is overriding your valuesCheers!
Hi guys,
I'm trying to render a fileUpload field. But { property: images, type: file } does not work. How can I do this?
BR,
Dennis
I've got it working.
- { property: 'images', type: 'file', type_options: { multiple: true } }
Now I'm going to figure out how to handle the files.
Hey Dennis,
Glad you got it working, well done! And thanks for sharing the solution with others. Let us know if you have further problems.
Cheers!
Heya everybody!,
First I like to say I love these tutorials. They do help me a lot to find my way through the Symfony-Jungle. <3
Still, I do have a question: I am using type: country for a field. I do want a placeholder as first entry like 'please choose'. Is this possible?
Kind regards
Hey Sebastian!
We are very happy to hear that you are liking our tutorials :)
About your question, there is a easy way to add a placeholder, just add this to your entity form config
Cheers!
"Houston: no signs of life"
Start the conversation!