How to override Symfony form MoneyType input as type=“number”?

前端 未结 4 876
天命终不由人
天命终不由人 2021-01-18 09:54

The Symfony MoneyType Field renders as input type=\"text\" which allows a user to type whatever they want into the field.

How can I override this to ren

4条回答
  •  不思量自难忘°
    2021-01-18 10:41

    You should be able to override the default field template:

    {%- block form_widget_simple -%}
        {%- set type = type|default('text') -%}
        
    {%- endblock form_widget_simple -%}
    
    .... other templates ....
    
    {%- block money_widget -%}
        {{ money_pattern|replace({ '{{ widget }}': block('form_widget_simple') })|raw }}
    {%- endblock money_widget -%}
    

    by

    {%- block money_widget -%}
        
    {%- endblock money_widget -%}
    

    In a custom template definition

    app/Resources/views/form/fields.html.twig

    For more information about how to override fields templates see this doc:

    http://symfony.com/doc/current/cookbook/form/form_customization.html#method-2-inside-a-separate-template

提交回复
热议问题