becklyn/ordered-form-bundle

此包添加了对表单元素排序的功能

安装次数: 21,883

依赖项: 1

建议者: 1

安全性: 0

星标: 5

关注者: 2

分支: 1

开放问题: 0

类型:symfony-bundle

1.4.0 2024-01-17 12:49 UTC

This package is auto-updated.

Last update: 2024-09-17 14:27:47 UTC


README

一个使表单字段可排序的包。

安装

composer require becklyn/ordered-form-bundle

使用

此包添加了一个新的表单选项,名为 position

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;

class SomeForm extends AbstractType
{
    /**
     * @inheritDoc
     */
    public function buildForm (FormBuilderInterface $builder, array $options) : void
    {
        $builder
            ->add("field", null, [
                "position" => /* some value */
            ]);
    }
}

支持的值包括

注意事项

此包侧重于速度,因此排序可能不是完美的。由于存在冲突的可能性,此包尝试最佳排序,但这意味着

  • 一个 first 字段不一定是最前面的(例如,如果有多个 first)。
  • beforeafter 只保证相对顺序,而不是这些字段之间的距离大小(它试图将它们立即放置在一起)。

如果表单配置合理且无冲突,则顺序将按预期工作。