操作表单。

0.0.0 2023-03-11 15:08 UTC

This package is auto-updated.

Last update: 2024-08-31 00:37:15 UTC


README

这个库帮助操作表单。

安装

使用 Composer 安装包

composer require atournayre/form

功能

  • 将maxlength属性添加到所有文本字段

示例

namespace App\Subscriber\Form;

use Atournayre\Helper\Decorator\Form\MaxLengthFormDecorator;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;

class FormDecoratorSubscriber implements EventSubscriberInterface
{
    public static function getSubscribedEvents(): array
    {
        return [
            FormEvents::PRE_SET_DATA => 'onPreSetData',
        ];
    }

    public function onPreSetData(FormEvent $event)
    {
        $form = $event->getForm();
        // Add a maxlength attribute to all text fields.
        MaxLengthFormDecorator::decorate($form);
    }
}

贡献

欢迎对包的贡献!

许可证

此包的所有内容均受MIT许可证许可。