2013-07-25 37 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

这是不是一个错误,这是一个特点。

相关问题