douan3019 2017-05-05 14:26
浏览 75
已采纳

在Symfony 3.1.1表单的输入文本字段中添加掩码

Solution:

Solved it! Instead of installing the plugin via the composer, I manually copied and pasted the jquery-mask js file content and imported it. :)

Question:

I need to add a mask into a text field of a Symfony 3.1.1 form. This is the form I am rendering:

{# E-mail // Usuario #}
<div class="row">
    <div class="col-md-5  col-md-offset-1">
        E-mail<span style="color: #217db1;">*</span></br>
        {{ form_widget(form.email, { 'attr': {'class': 'formularioRegistro'} }) }}
        {{ form_errors(form.email) }}
    </div>
</div>

<div class="row">
    {# CPF #}
    <div class="col-md-5 col-md-offset-1">
        CPF (somente números)<span style="color: #217db1;">*</span></br>
        {{ form_widget(form.cpf, { 'attr': {'class': 'formularioRegistro'} }) }}
        {{ form_errors(form.cpf) }}
    </div>
</div>

I want to add the mask for the CPF field, which should have the following format: "_ _ _ . _ _ _ . _ _ _ - _ _". I mean, "3 digits point 3 digits point 3 digits slash 2 digits".

I tried to use javascript referencing the input id, but had no success.

  • 写回答

2条回答 默认 最新

  • drex88669 2017-05-05 14:44
    关注

    Use this jquery plugin.

    https://igorescobar.github.io/jQuery-Mask-Plugin/

    In the Form:

    $builder->add(
                'property', TextType::class, array(
                'required' => false,
                'attr' => ['data-mask' => '000.000.000-00']
                'placeholder' => '_ _ _ . _ _ _ . _ _ _ - _ _'
            ));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上