Symfony2: Extending the twig date field
I would like to override the existing date field type so that I can use a js component. I tried so far:
{% block date_widget %}
{% spaceless %}
<input typ开发者_运维知识库e="text" {{ block('attributes') }} readonly="true" value="{{ value }}"/>
<script>
mycal = new dhtmlxCalendarObject("{{ id }}");
mycal.setSkin('yahoolike');
mycal.setDateFormat('%d.%m.%Y');
mycal.loadUserLanguage("de");
mycal.draw();
</script>
{% endspaceless %}
{% endblock date_widget %}
It doesn't work so far (the js component is shown, but with no function), my questions are: in value
, I need the date representation as a string like '31.12.2011', but value
seems to be an empty array.
Another question: how can twig/sf2 then recognize the result? The components writes the date as string in the input field, but sf gives me an error
Expected argument of type "array", "string" given
I use Symfony 2.0, Beta 5
I succeeded - my error was that I forgot to specify the 'widget'-option as single text: 'widget' => 'single_text'.
Here is my FormBuilder:
$builder->add('abgabedatum', 'date', array('label' => 'Abgabedatum', 'widget' => 'single_text'));
and my entry in fields.html.twig (my form_theme)
{% block date_widget %}
{% spaceless %}
<input type="text" {{ block('attributes') }} readonly="true" value="{{ value }}"/>
<script>
mycal = new dhtmlxCalendarObject("{{ id }}");
mycal.setSkin('yahoolike');
mycal.setDateFormat('%d.%m.%Y');
mycal.loadUserLanguage("de");
mycal.draw();
</script>
{% endspaceless %}
{% endblock date_widget %}
精彩评论