05.
Form Theming: Add an Error Icon
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.
6 Comments
Hey, can anybody tell me is there a way to pass direct unconventional params to form_row
{{ form_row(form.fullName, {'iconClass': 'cat'}) }}
{{ form_row(form.fullName, {'iconClass': 'dog'}) }}
and then inside row just read?
I see iconClass in dump() while debug
{% block form_row %}
{{ dump() }}
but when I try to access it
{{ iconClass }}
I have an error that variable is undefined. Very strange behavior
{% endblock %}
I use symfony 4.4.
Hey Yehor!
That looks correct! I wonder if the error is actually occurring because you have a
form_row()on some other fields and - since you're not passingiconClassto that form row, it's causing an error.Try doing something like this:
That should avoid a "variable is undefined" error if you don't pass this variable.
Cheers!
When adding the _formTheme.html.twig to config.yml I had to set a relative path to the file from the views folder so admin/genus/_formTheme.html.twig
I am using Symfony 3.1.4 so just the version downloaded from this tutorial.
What am I doing wrong / different to cause this change in behaviour?
Hey Bananaapple
Yeah, you have to do that if your form theme does not live at the root of "app/Resources/views"
Have a nice day
I have some problem.
In EDIT form, if I'm choice option 'Select subfamily' (placeholder) in list of Subfamily, Symfony will show error:
Type error: Argument 1 passed to AppBundle\Entity\Genus::setSubFamily() must be an instance of AppBundle\Entity\SubFamily, null given, called in D:\OpenServer\domains\aquanote.local\vendor\symfony\symfony\src\Symfony\Component\PropertyAccess\PropertyAccessor.php on line 636
In ADD form all work fine - correctly handles the wrong choice and displays under SELECT field the error message.
Hey Nikolay!
This is happening because you are choosing the placeholder option, which is not a SubFamily, and since your setSubFamily() method does not allow null to be passed, it explodes. So, you have two choices, allow passing null or validate the SubFamily field.
Cheers!
"Houston: no signs of life"
Start the conversation!