Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Components][Form] describe how to access form errors#4168

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
weaverryan merged 1 commit intosymfony:2.3fromxabbuh:issue-3660-2.3
Oct 28, 2014

Conversation

xabbuh
Copy link
Member

QA
Doc fix?yes
New docs?no
Applies toall
Fixed tickets

ThegetErrors() andgetErrorsAsString() methods haven't been documented before. This pull request adds a short description for them. This forms as basis for the solution of#3660.


Unless you enable the :ref:`error_bubbling <reference-form-option-error-bubbling>`
option on a particular child form, ``getErrors()`` only returns the errors
of the form it is accessed on. For debugging purposes, you can use the :method:`Symfony\\Component\\Form\\Form::getErrorsAsString` method which
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

unless you set$deep totrue

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Where do you want to set$deep to true?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

sorry, I missed your next PR. This comment is no longer true.

(fyi, I responded to "Unless you enable the error_bubbling option on a particular child form,getErrors() only returns the errors of the form it is accessed on.")

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

No problem. Now that I understand your concerns. :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think this note is a bit more abstract than I'd like. Here are the main points I'd like to say:

  1. CallinggetErrors() on the main form object only returns global form errors
  2. CallinggetErrors(true) will returnall of the form objects, but there's no way to know which field each is attached to
  3. Calling$form['firstName']->getErrors() will return you errors for only thefirstName field
  4. CallinggetErrorsAsString() is easy for debugging.

There are a lot of questions about form errors on stackoverflow etc. and don't think we have details anywhere currently. So I'd like to fully explain how to do what you want. The only unfortunate thing (I think there was an issue/PR about this) is thatgetErrors(true) doesn't return any way (as far as a I can see) to know which error is attached to which field.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Bah, nevermind - now I see that#4169 is here for the 2.5 features and that this is for 2.3.

So, obviously ignore (2), but I still think we should do 1, 3 and 4.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@xabbuh I see that you put#4169 on hold for this, so I came back. I think we should basically expand your code block to show 1, 3 and 4 in my above note, with a comment for each that says what they do:

// an array of FormError objects, but only errors attached to this form level (e.g. "global errors)$errors =$form->getErrors();// an array of FormError objects, but only errors attached to the "firstName" field$errors =$form['firstName']->getErrors();// ... etc

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

... because nobody reads words, so let's show all the code right next to each other :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

friendly ping@xabbuh! :)

@xabbuhxabbuhforce-pushed theissue-3660-2.3 branch 2 times, most recently from3a7a1cc to71a8072CompareOctober 20, 2014 21:13
@xabbuh
Copy link
MemberAuthor

I'm really sorry for the delay, but I finally managed to update the pull request.

If you enable the :ref:`error_bubbling <reference-form-option-error-bubbling>`
option on a form, ``getErrors()`` will also return errors attached to
child forms, but there is no way to determine which field an error is
attached to.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Sorry, now that I read this note more closely, I'm not sure I agree (or probably more likely, I'm not sure it's phrased correctly). Itsounds like you can seterror_bubbling totrue on the top-level form and then all the errors of the child fields will bubble up to it. But I don't think that's the case - it's set on a field, and then that field's error bubble to the form.

If I'm right, how about something like this:

If you enable theerror_bubbling option on a field, callinggetErrors() on the parent
form will include errors from that field. However, there is no way to determine which
field an error was originally attached to.

Thanks! And no worries about the delay - I'm catching up my self. And nice work with the above changes.

@xabbuh
Copy link
MemberAuthor

@weaverryan Of course, you're right.

@weaverryan
Copy link
Member

Thanks Christian - it looks great now! I'll merge this up so we can add the details special for 2.5. Cheers!

@weaverryanweaverryan merged commit5deccd2 intosymfony:2.3Oct 28, 2014
weaverryan added a commit that referenced this pull requestOct 28, 2014
…xabbuh)This PR was merged into the 2.3 branch.Discussion----------[Components][Form] describe how to access form errors| Q             | A| ------------- | ---| Doc fix?      | yes| New docs?     | no| Applies to    | all| Fixed tickets |The ``getErrors()`` and ``getErrorsAsString()`` methods haven't been documented before. This pull request adds a short description for them. This forms as basis for the solution of#3660.Commits-------5deccd2 describe how to access form errors
@xabbuhxabbuh deleted the issue-3660-2.3 branchOctober 28, 2014 08:45
weaverryan added a commit that referenced this pull requestNov 20, 2014
…rors() (xabbuh)This PR was merged into the 2.5 branch.Discussion----------[Components][Form] document $deep and $flatten of getErrors()| Q             | A| ------------- | ---| Doc fix?      | no| New docs?     | yes (symfony/symfony#9918)| Applies to    | 2.5+| Fixed tickets |#3660This is based on#4168.Commits-------0245e91 [Form] document $deep and $flatten of getErrors()4221db8 describe how to access form errors
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@xabbuh@weaverryan@wouterj

[8]ページ先頭

©2009-2025 Movatter.jp