it / input-mask-bundle
一个简单的Symfony组件,实现了RobinHerbots/Inputmask jQuery插件的表单类
1.3.0
2020-07-16 13:58 UTC
Requires
- php: >=5.6
- symfony/framework-bundle: 2.8.*|3.*|4.*|5.*
- twig/twig: *
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/Inputmask 或 http://robinherbots.github.io/Inputmask/