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

Add mask in an input text field in Symfony 3.1.1 form

解法:

解决了!我没有通过 composer 安装插件,而是手动复制并粘贴 jquery-mask js 文件内容并导入它。 :)

问题:

我需要将掩码添加到 Symfony 3.1.1 表单的文本字段中。这是我呈现的形式:

{# 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>

我想为 CPF 字段添加掩码,其格式应为:“_ _ _ . _ _ _ . _ _ _ - _ _”。我的意思是,“3 位数字 point 3 位数字 point 3 位数字 slash 2 位数字”。

我尝试使用 javascript 引用输入 ID,但没有成功。

你是说占位符吗?如果是这样,如果你的表格 class:

use Symfony\Component\Form\Extension\Core\Type\TextType;

$builder->add('property', TextType::class, array(
    'required'    => false,
    'placeholder' => '_ _ _ . _ _ _ . _ _ _ - _ _'
));

使用这个 jquery 插件。

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

在表格中:

$builder->add(
            'property', TextType::class, array(
            'required' => false,
            'attr' => ['data-mask' => '000.000.000-00']
            'placeholder' => '_ _ _ . _ _ _ . _ _ _ - _ _'
        ));