1

I'm struggling with several things relating to dates and times in forms.

I have a date on a form and I'm using the single_text widget.

My locale in parameters.yml is set to en_US.

config.yml has under framework:

default_locale: %locale%

I expected it to accept mm/dd/yyyy but that produces "This value is not valid." when I try input 1/1/2012 on my form and submit. The only way I can get it to work is to set format => 'MM/dd/yyyy' in code in the options array when adding the widget.

I guess I've missed something.

1 Answer 1

1

The default format for the date form type is IntlDateFormatter::MEDIUM, which is a date format which depends on your locale, but which probably is different from what you expect. For en_US this format is MMM d, y, so it expects something like jan 01, 2012. If you want to use the MM/dd/yyyy format, just set format in the options array as you did.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.