-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Added doc entry for delete_empty form option with callable #8510
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
reference/forms/types/collection.rst
Outdated
// ... | ||
'delete_empty' => function ($obj = null) { | ||
return null === $obj || empty($obj->firstName); | ||
}, |
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.
The users
field suggests a collection of type User
, right?
'delete_empty' => function (User $user = null) {
return null === $user || empty($user->getFirstName());
},
Something like this would be good for you?
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.
Yes! I've updated the code example.
reference/forms/types/collection.rst
Outdated
A value is deleted from the collection only if the normalized value is ``null``. | ||
However, you can also set the option value to a ``callable``, which will be called | ||
for each value in the submitted collection. The ``callable`` should return | ||
whether or not a value must be removed from the collection. For example:: |
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.
The feature is especially useful for compound type entries only, we should mention it somewhere.
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.
Yes. I've added a sentence explaining that use case after the code example.
@yceruto I've added your comments to the commit. Thanks. |
We might have to add |
- Added User type hint - Added sentence about compound collection type use case - Added versionadded block
@yceruto Done! |
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.
Nice! Thanks for documenting this.
reference/forms/types/collection.rst
Outdated
@@ -286,6 +286,27 @@ the empty values will be kept. | |||
Read about the :ref:`form's empty_data option <reference-form-option-empty-data>` | |||
to learn why this is necessary. | |||
|
|||
A value is deleted from the collection only if the normalized value is ``null``. | |||
However, you can also set the option value to a callable, which will be executed | |||
for each value in the submitted collection. If the callable returns ``false``, |
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.
This looks wrong to me. The item is removed if the callable returns true
, isn't?
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.
Yes, of course! Edited.
reference/forms/types/collection.rst
Outdated
may define complex conditions for considering them empty. | ||
|
||
.. versionadded:: 3.4 | ||
Using a callable for the ``delete_empty`` option was introduced in Symfony 3.4. |
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.
Support for using a callable [...]
Thank you @hiddewie. |
Btw, this is a pretty cool feature. So extra thanks for doc'ing it and to @Koc for the feature! |
…ble (hiddewie, javiereguiluz) This PR was merged into the 3.4 branch. Discussion ---------- Added doc entry for delete_empty form option with callable Fix #8244. I hope the explanation is clear enough. Now it is just an addition to the existing text. The piece of code is taken from the tests (adapted slightly for simplicity). Commits ------- 0373a97 Processed xabbuh comments 3f1a814 Minor rewords 1722628 Added doc entry for delete_empty form option with callable
Fix #8244.
I hope the explanation is clear enough. Now it is just an addition to the existing text. The piece of code is taken from the tests (adapted slightly for simplicity).