2013-07-25 36 views
0

當我這樣做:Symfony2的日期字段類型的格式選項,更改輸入類型爲文本

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

我得到:

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

類型是「日期」

但是當我添加格式選項字段:

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

I得到:

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

輸入類型現在是'文本'。

我在jQuery中根據[type =「date」]做了幾件事情。當它更改爲「文本」時,我的所有行爲都不起作用。

任何想法,爲什麼是這樣,如何解決它,任何解決方法嗎?

+0

我有完全相同的問題。你找到了解決辦法嗎? – Stefan

+0

沒有解決辦法,只是解決方法。我爲所有類型爲date的字段添加了一個css類。但是,我不得不改變我的js和css。我仍然希望有更好的解決方案。 – tiriana

+0

我在symfony bug跟蹤器上發了一張票,希望它能幫上忙。 https://github.com/symfony/symfony/issues/8726 – tiriana

回答

3

所以我剛剛從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) 

的評論是:

// 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

這是不是一個錯誤,這是一個特點。

相關問題