Thanks to visit codestin.com
Credit goes to github.com

Skip to content

TextType empty_data = null if string is empty #7596

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

Closed
markoffk opened this issue Mar 8, 2017 · 8 comments
Closed

TextType empty_data = null if string is empty #7596

markoffk opened this issue Mar 8, 2017 · 8 comments
Labels
Form hasPR A Pull Request has already been submitted for this issue.

Comments

@markoffk
Copy link

markoffk commented Mar 8, 2017

Q A
Bug report? yes
Symfony version 3.2.4

Hello.

I am getting null value after passing empty string to symfony form field.
After defining empty_data in form builder, the problem has gone:

        $builder
            ->add('name', TextType::class, [
                'empty_data'  => '',
            ])

But documentation claims that empty_data is empty string ('') by default. So either the documentation should be changed or behavior of form field type.

Link to docs: http://symfony.com/doc/current/reference/forms/types/text.html#empty-data

Thanks.

@HeahDude
Copy link
Contributor

The feature has been introduced in 3.1 in symfony/symfony#18357, but the target should now be 3.2. It would be easier to handle it once #6265 is merged.

@curry684
Copy link
Contributor

curry684 commented Mar 28, 2017

Why was this put on hold? More people are running into this, see symfony/symfony#22192

@HeahDude HeahDude added hasPR A Pull Request has already been submitted for this issue. and removed On hold labels Mar 28, 2017
@HeahDude
Copy link
Contributor

Hi @curry684, I've changed the label, see ##6265, empty_data option needs a revamp, and some more work on symfony 2.7. I've changed the label to better indicate the status.

@bodograumann
Copy link

bodograumann commented Mar 29, 2017

I have just encountered this bug. Is it a problem in the documentation or do you intent to change the behavior of the TextType?

@HeahDude
Copy link
Contributor

The behavior is now null by default or empty string if explicitly configured (which not possible before symfony/symfony#18357), this cannot change for BC.

But it may be the opposite in 4.0, I'm working on it (no PR is open yet) but this is not as simple as it sounds :).

xabbuh added a commit that referenced this issue May 4, 2017
…s more visisble (HeahDude, wouterj, javiereguiluz)

This PR was merged into the 2.7 branch.

Discussion
----------

[Form] Make difference between data and empty_data options more visisble

Finishes #6265
Fixes #7299, #7596

Commits
-------

64e3984 Fixed a minor typo
df9b878 Fixed a minor typo
f375489 Better explain empty_data values
d552ea3 Readd mixed type for empty_data, it can be string, array or object
188f0ab Tried to write the important points more explicitly
5f3813d Updated the example add added a caution
4fd2d96 Addressed @stof's comment
242941a improved accuracy
67c93b6 fix typo
87b3542 explicit differences between 'data' & 'empty_data' in FormType
@xabbuh xabbuh closed this as completed May 4, 2017
@xabbuh xabbuh reopened this Nov 9, 2018
@xabbuh
Copy link
Member

xabbuh commented Nov 9, 2018

We need to update the empty_data option description for the text type to reflect that the default is null, but that you can opt-in for the empty string (see symfony/symfony#18357).

@xabbuh
Copy link
Member

xabbuh commented Nov 9, 2018

see also symfony/symfony#29061 for problems one runs into when reading the current description

@HeahDude
Copy link
Contributor

HeahDude commented Dec 8, 2018

Fixed in #10743. Closing here, thanks for the report.

@HeahDude HeahDude closed this as completed Dec 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Form hasPR A Pull Request has already been submitted for this issue.
Projects
None yet
Development

No branches or pull requests

5 participants