Skip to content

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

Merged
merged 4 commits into from
Mar 18, 2014

Conversation

mtrojanowski
Copy link
Contributor

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

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``:
Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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!

Copy link
Member

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 :).

@mtrojanowski
Copy link
Contributor Author

While inspecting this issue I started to wander if this fragment is adequate (same file, line 773):

  You can also customize the error output for just one specific field type.
  For example, certain errors that are more global to your form (i.e. not specific
  to just one field) are rendered separately, usually at the top of your form:

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?

@stof
Copy link
Member

stof commented Feb 5, 2014

@mtrojanowski you can. It works exactly the same way than customizing the widget of a field (except that the block name ends with _errors instead of _widget)

@mtrojanowski
Copy link
Contributor Author

@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.

@mtrojanowski
Copy link
Contributor Author

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 %}
Copy link
Member

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 :)

Copy link
Member

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 :)

@mtrojanowski
Copy link
Contributor Author

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::
Copy link
Contributor Author

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

Copy link
Member

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

@mtrojanowski
Copy link
Contributor Author

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?

@weaverryan
Copy link
Member

Woot, thanks Michał! :)

weaverryan added a commit that referenced this pull request Mar 18, 2014
…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.
@weaverryan weaverryan merged commit 6f6fcca into symfony:2.3 Mar 18, 2014
@mtrojanowski
Copy link
Contributor Author

Always a pleasure :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants