10000 [Form] DateTimeType displays duplicate "invalid" error · Issue #4359 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
8000

[Form] DateTimeType displays duplicate "invalid" error #4359

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
webmozart opened this issue May 21, 2012 · 7 comments
Closed

[Form] DateTimeType displays duplicate "invalid" error #4359

webmozart opened this issue May 21, 2012 · 7 comments

Comments

@webmozart
Copy link
Contributor

DateTimeType, when used with the widget "text", currently duplicates the invalid error when an invalid value is entered.

Also, it should be possible to configure the "invalid" messages of both the "date" and the "time" field.

@webmozart
Copy link
Contributor Author

See also #2326 for a previous, but insufficient solution.

@gh0stonio
Copy link

Hi, i try to solve this issue, but i can't reproduce the first part with the duplicate invalid error message.
I create my form based on DateTimeType using the widget "text" and try several condition to fail the submit but all the time i only get one invalid error message for the invalid value but not one for both.

Maybe i misunderstand the issue, but right now i didn't find any problem here for the duplicate error message.

Can anyone explain me better, to help me to find it ?

Thx

@craue
Copy link
Contributor
craue commented Jul 13, 2012

I also just noticed this with a date field consisting of three choice parts.

To reproduce it:
Let's say there's 'years' => range(1990, 2000) passed as an option to the date field. When now a year outside of that range is submitted, you'll get two errors saying This value is not valid., one from the date field itself because of an invalid date and one from the year field (which bubbles up to the date field since #4850) because of the invalid year value.

@webmozart
Copy link
Contributor Author

Thanks for posting these infos @craue.

@webmozart
Copy link
Contributor Author

To sum up, the problem is that if you enter an invalid date

  • the date field is marked as invalid and the error bubbles up
  • the datetime is marked as invalid, the error remains

If I'm not mistaken, the solution is not to mark any form invalid if any of their children is invalid as well (invalid = not synchronized in this context). Duplicate invalid messages don't really help the user, we only want to keep the most specific ones.

Any objections?

@webmozart
Copy link
Contributor Author

This is implemented now in the referenced PR.

fabpot added a commit that referenced this issue Nov 9, 2012
This PR was merged into the 2.1 branch.

Commits
-------

4909bc3 [Form] Fixed forms not to be marked invalid if their children are already marked invalid

Discussion
----------

[Form] Fixed forms not to be marked invalid if their children are already marked invalid

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: #4359
Todo: -
License of the code: MIT
Documentation PR: -

This PR prevents unsynchronized forms from being marked invalid if any of their children is also unsynchronized (and thus also marked invalid). Displaying an invalid message twice does not help the user and, if used in conjunction with error bubbling, may lead to duplicate errors (see #4359).
@fabpot fabpot closed this as completed Nov 9, 2012
@floriansemm
Copy link

@webmozart I think there is still a problem:

Our user-entity has a gender property with the following validation:

gender:
    - NotBlank:
        groups: [default]
        message: Choose a gender.
    - Choice:
        choices:  [male, female]
        message:  Wrong gender.

If the submitted value is not "male" or "female" the error-message "This value is invalid" is displayed and not the message from the validation configuration. The second problem is the choice-validation is never executed.

The reason is this if-statement: https://github.com/symfony/Form/blob/d5f40a333d6bf209230875b58e8c8da2e2caae7e/Extension/Validator/Constraints/FormValidator.php#L98

My fix for the first problem is to configure a invalid_message. But I have no idea how to fix the second problem.

$builder->add('gender', 'choice', array(

    'label' => 'Gender',

    'choices' => array(

        // ....
    ),
    
    'widget_type' => 'inline',
    
    'expanded' => true,
    
    'required'  => true,
   
    'invalid_message' => 'Invalid gender'

));

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

No branches or pull requests

5 participants
0