-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] Unwanted Validation on DateTime Type #7182
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
Turns out that after ac69394 invalid_message and invalid_message_parameters are no longer being propagated to datetime's children. What was the rationale for removing this, @bschussek? |
This is really annoying... |
The form framework itself also applies some validation. In this case it tries to transform the input to a DateTime object in a Transformer which fails. Such errors only get a generic "invalid" error message which cannot be customized. This is a known limitation. |
Subscribing. I do have the same issue with a datetime field not validating whatever I do, with the same generic failure message. Edit: I've just found @bschussek's comment on Stackoverflow regarding this (http://stackoverflow.com/a/18367705/2373960) and I guess I've figured out where exactly my validation error stems from. |
Using a custom form type is the only solution that comes to my mind. |
Quick write up of what I did to get this working. Might not be the best solution, but it works. The default widget with datetime is the 'choice' widget, which returns an array of values (year, month, day, ...) instead of a string. However, my widget returned a string, which made the Transformer fail with "Compound forms expect an array or NULL on submission." and thus the "This value is not valid" error message. So what I did was to configure the datetime field to use single_text as its widget, with my custom widget overriding this to render a bootstrap enabled datetimepicker. Before that, I had overwritten the default datetimewidget, thus the choice widget, which of course wouldn't work. |
Fixed in #9453. |
You need to set the widget to single_text: |
@chaos-drone Please check if the issue persist with the latest 2.8 patch release (2.8.8 at this time) and open a new issue then. |
Hi there,
I have notice that for a datetime Type, an automatic validation is done after form submiting.
I splitted my field like this:
If I put for example "02/35/2013" in my matchDate.date field, I get an error on the matchDate field with "This value is not valid".
I looked in Symfony\Component\Validator\Constraints\Date.php, Symfony\Component\Validator\Constraints\Time.php, Symfony\Component\Validator\Constraints\DateTime.php and anywhere I could find this error message.
On my entity I have no validation constraints set. Did anyone notice the same behavior on this application ?
In fact, it's not a problem that the validation is done, it's more the unposibility to change the error message even in setting the 'invalid_message' option.
Thanks in advance for you help.
By the way, I'm actualy working on 2.2.0BETA1
The text was updated successfully, but these errors were encountered: