0

When i do:

    $builder->add('submittedAt_min',
                    'date',
                    array('widget' => 'single_text', 'label' => 'my label', 'attr' => array('placeholder' => 'my placeholder')));

i get:

    <input type="date" placeholder="my placeholder" required="required" name="es_app_filter[submittedAt_min]" id="es_app_filter_submittedAt_min" class="hasDatepicker">

The type is "date"

But when I add format option to field:

    $builder->add('submittedAt_min',
                    'date',
                    array('format' => 'dd-MM-yyyy', 'widget' => 'single_text', 'label' => 'my label', 'attr' => array('placeholder' => 'my placeholder')));

I get:

      <input type="text" placeholder="my placeholder" required="required" name="es_app_filter[submittedAt_min]" id="es_app_filter_submittedAt_min">

the input type is now 'text'.

I do several things in jQuery basing on [type="date"]. When it changes to "text" all my action wont work.

Any ideas why is it this way, how to fix it, any workaround?

4
  • no solution, just workaround. I added a css class to all my fields of type date. However, I had to change my js and css. I'm still hoping for better solution. Commented Aug 12, 2013 at 19:07
  • I made a ticket at symfony bug tracker, hope it'll help. github.com/symfony/symfony/issues/8726 Commented Aug 12, 2013 at 19:16
  • ok, thx - hope we get a solution from the bugtracker... Commented Aug 13, 2013 at 7:32
  • I got the answer from Symfony, and put in in here as well. It explains everything, but is far from satisfactory. Commented Aug 21, 2013 at 11:08

2 Answers 2

3

So I just got answer from Symfony IssueTracker.

See comment here https://github.com/symfony/Form/blob/master/Extension/Core/Type/DateType.php#L130
The field type is set to "date" only if the format matches the one expected by HTML5 ( yyyy-MM-dd ) 

The comment is:

    // Change the input to a HTML5 date input if
    //  * the widget is set to "single_text"
    //  * the format matches the one expected by HTML5
    if ('single_text' === $options['widget'] && self::HTML5_FORMAT === $options['format']) {
        $view->vars['type'] = 'date';
    }

https://github.com/symfony/Form/blob/master/Extension/Core/Type/DateType.php#L130

It's not a bug, it's a feature.

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

Comments

0

Have you tried putting format after widget in the array (like the example on the symfony2 docs)? http://symfony.com/doc/current/reference/forms/types/date.html#format

1 Comment

It's associative array, order does not matter.

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.