tiitoo/input-mask-bundle

一个简单的Symfony扩展包,实现了RobinHerbots/Inputmask jQuery插件的表单类。

安装: 6

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 5

类型:symfony-bundle

1.2.0 2019-02-14 11:19 UTC

This package is auto-updated.

Last update: 2024-09-19 00:21:56 UTC


README

这是一个简单的Symfony扩展包,实现了RobinHerbots/Inputmask jQuery插件的表单类。

安装

使用composer进行安装

composer require it/input-mask-bundle

在项目中启用此扩展包(仅适用于Symfony 2-3。Sf4会自动完成此操作)

// app/AppKernel.php
public function registerBundles()
{
    $bundles = array(
        // ...
        new IT\InputMaskBundle\ITInputMaskBundle(),
        // ...
    );
}

配置

Symfony 2-3方法

将以下行添加到您的config.yml文件中

# app/config/config.yml

twig:
    form_themes:
        - 'ITInputMaskBundle:Form:inputMaskFields.html.twig'

Symfony 4方法

# config/packages/input_mask.yml
# Or in config/packages/twig.yml

twig:
    form_themes:
        - '@ITInputMask/Form/inputMaskFields.html.twig'

用法

您可以在您的Symfony表单中使用以下类型

    // Will result of a single_widget date picker
    use IT\InputMaskBundle\Form\Type\DateMaskType;
    use IT\InputMaskBundle\Form\Type\EmailMaskType;
    use IT\InputMaskBundle\Form\Type\UrlMaskType;
    //...
    $builder
        ->add('birthdate', DateMaskType::class, array(
            'label' => 'Date of birth',
        ))
        ->add('email', EmailMaskType::class, array(
            'label' => 'Email field',
        ))
        ->add('url', UrlMaskType::class, array(
            'label' => 'Url field',
        ))
    ;

或者

    // Will result of a text widget with the format "[0-9]{2}\.[0-9]{2}\.[0-9]{2}\.[0-9]{2}\.[0-9]{2}"
    use IT\InputMaskBundle\Form\Type\TextMaskType;
    //...
    $builder
        ->add('phone', TextMaskType::class, array(
            'label' => 'Phone number',
            'mask' => '99.99.99.99.99'
        ))
    ;

或者使用正则表达式类型

    // Will result of a text widget with the format "[0-9]{2}\.[0-9]{2}\.[0-9]{2}\.[0-9]{2}\.[0-9]{2}"
    use IT\InputMaskBundle\Form\Type\TextMaskType;
    //...
    $builder
        ->add('phone', RegexMaskType::class, array(
            'label' => 'Phone number',
            'regex' => '[0-9]{2}\.[0-9]{2}\.[0-9]{2}\.[0-9]{2}\.[0-9]{2}'
        ))
    ;

有关"mask"配置的详细信息,请参阅RobinHerbots/Inputmask文档:https://github.com/RobinHerbots/Inputmaskhttp://robinherbots.github.io/Inputmask/