-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] isEmpty #13940
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
Comments
Hi @nino-s, thank you for such a detailed issue. The case you describe should be fixed by the This is also demostrated in this test case: https://github.com/symfony/Form/blob/master/Tests/Extension/Core/Type/CollectionTypeTest.php#L145-166 (fixtures: Can you show some more context about how you're using the form component to see what's going wrong? |
I dont know what went wrong, but after I cleared the cache complettly, I checked it again and the error was gone. As I already described, it happened for a simple collection with more than one field (in form type) after I added asserts to each field. |
Hmm, in that case, I would close this issue and reopen it if the error occurs once more. Probably, there was some old cache causing this behaviour |
@nino-s feel free to re-open if you manage to reproduce this issue. |
…on. (Koc) This PR was merged into the 3.4 branch. Discussion ---------- [Form] Allow pass filter callback to delete_empty option. | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #13601, #13940, #22008, #22014 | License | MIT | Doc PR | coming soon Commits ------- 8630abe [Form] Allow pass filter callback to delete_empty option.
The method
isEmpty
checks the input form data. It checks for simple nullable elements, empty strings, empty arrays and empty traversables. Am i wrong? If i have an object, which consist only of empty collections, nullable fields etc., shouldn't it check such an 'empty' object and return true aswell?Following use case: I have an embedded collection in an entity form. It's attributes have some asserts (notnull, empty, etc.). Adding and Removing with prototype works perfectly, but if i just add a new entry and enter nothing, it should delete the entry on submit with the flag
delete_empty
. Actually, it does not, becausemodelData
is an object, therefore not empty and the standard validation errors occur.Current
isEmpty
method:My idea would be, to additionally check if
modelData
is an object and if the object has a self madeisEmpty
method. (A generic version is also possible - all getter)(is_object($this->modelData) && method_exists($this->modelData, 'isEmpty') && call_user_func(array($this->modelData, 'isEmpty')))
Best regards,
Nino
The text was updated successfully, but these errors were encountered: