it/input-mask-bundle

一个简单的Symfony组件,实现了RobinHerbots/Inputmask jQuery插件的表单类

安装量: 69,549

依赖者: 0

建议者: 0

安全: 0

星标: 8

关注者: 2

分支: 5

开放问题: 0

类型:symfony-bundle

1.3.0 2020-07-16 13:58 UTC

This package is auto-updated.

Last update: 2024-09-16 22:58:30 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/