-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Fix the definition of customizing form's global errors. #3543
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
as above, but now call the block ``form_errors`` (Twig) / the file ``form_errors.html.php`` | ||
(PHP). Now, when errors for the ``form`` type are rendered, your customized | ||
fragment will be used instead of the default ``form_errors``. | ||
as above, but now check if the ``compound`` attribute is set to ``true``: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure which is more correct for the compound
- attribute or varaible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd add also an example block as in #3542. This way it's easier for new comers understand what to do without searching for something that simply does not exist. Wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if I understand you correctly. There is an example block below this line. Do you think that anything else should be added?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AH! Shame on me :) Just replied to your comment and didn't see the rest. Well looks good to me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd use "variable" - consistent with our conversation on "form variables" elsewhere.
Also, how about a small sentence about compound? Something like:
If the ``compound`` variable is ``true``, it means that what's being rendered is a collection of fields (e.g. a whole form), and not just an individual field.
Feel free to work on the wording - that's tough to get clear :).
While inspecting this issue I started to wander if this fragment is adequate (same file, line 773):
The first sentence suggests that you can customize the errors for each field type separately, but I don't think this is the case. Can anyone confirm if it's possible or is the sentence a bit misleading? |
@mtrojanowski you can. It works exactly the same way than customizing the widget of a field (except that the block name ends with |
@stof thanks. It's good to know. Maybe it's worth mentioning it in the docs implicitly. Now I think it's a bit to vague. I'll think of something and add to the PR. |
Added the note on how to customize errors for different field types. In fact I found this information in a sidebar a few sections above ("Knowing which block to customize"). Nevertheless I think it's better that all the information about the error customization is in one place (even if some of the information is doubled in the article). |
<li>{{ error.message }}</li> | ||
{% endfor %} | ||
</ul> | ||
{% endif %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about the else? We're not trying to customize the else case here, but of course without it, non-compound errors won't show up - so we'll need something :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw, @mtrojanowski happy to see you around here lately :)
the example code to contain `else` statements.
Took me a while but finally fixed the code according to the comments :) |
fragment will be used instead of the default ``form_errors``. | ||
as above, but now check if the ``compound`` variable is set to ``true``. | ||
|
||
.. tip:: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the part about the compound
var as a tip. Or would you rather leave it as a regular sentence in the text?
@weaverryan @wouterj
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would put it in a regular sentence
Applied the changes proposed by Wouter. As for the colons and semicolons in PHP templates I understand that I don't have to change anything there, right? |
Woot, thanks Michał! :) |
…rojanowski) This PR was merged into the 2.3 branch. Discussion ---------- Fix the definition of customizing form's global errors. The documentation for customizing global errors was actually still referring to the way it was done in 2.0. (where two different blocks were used: `field_errors` and `form_errors`). Since 2.1. only `form_errors` is used and errors are differentiated using the `compound` variable (set to `true` for form errors). | Q | A | ------------- | --- | Doc fix? | yes | New docs? | no | Applies to | 2.3+ | Fixed tickets | #3542 Commits ------- 6f6fcca Applied some changes according to comments. e3b20d8 Minor rewording. Added tip about meaning of `compound` var and expanded the example code to contain `else` statements. 1e278c4 Added note about customizing errors for different field types. 236d06b Fix the definition of customizing form's global errors.
Always a pleasure :) |
The documentation for customizing global errors was actually still referring to the way it was done in 2.0. (where two different blocks were used:
field_errors
andform_errors
). Since 2.1. onlyform_errors
is used and errors are differentiated using thecompound
variable (set totrue
for form errors).