kaistaerk/input-mask-bundle

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

安装: 113

依赖项: 0

建议者: 0

安全性: 0

星标: 0

关注者: 0

分支: 5

类型:symfony-bundle

1.0.1 2022-12-17 11:54 UTC

This package is auto-updated.

Last update: 2024-09-17 15:28:57 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/