跳到内容

ResetType 字段

编辑此页

一个将所有字段重置为其原始值的按钮。

渲染为 input reset 标签
父类型 ButtonType
ResetType

提示

此表单类型定义和继承的完整选项列表可通过在您的应用程序中运行此命令获得

1
2
# replace 'FooType' by the class name of your form type
$ php bin/console debug:form FooType

继承的选项

attr

类型: array 默认值: []

如果您想向按钮的 HTML 表示形式添加额外的属性,您可以使用 attr 选项。它是一个以 HTML 属性为键的关联数组。当您需要为按钮设置自定义类时,这非常有用

1
2
3
4
5
6
use Symfony\Component\Form\Extension\Core\Type\ResetType;
// ...

$builder->add('save', ResetType::class, [
    'attr' => ['class' => 'save'],
]);

disabled

类型: boolean 默认值: false

如果您不希望用户能够点击按钮,您可以将 disabled 选项设置为 true。将无法使用此按钮提交表单,即使绕过浏览器并手动发送请求(例如使用 cURL)也不行。

label

类型: stringTranslatableMessage 默认值: 标签从字段名称“猜测”而来

设置将显示在按钮上的标签。标签也可以直接在模板内设置

1
{{ form_widget(form.save, { 'label': 'Click me' }) }}

translation_domain

类型: string 默认值: messages

这是将用于为此按钮呈现的任何标签或选项的翻译域。

label_translation_parameters

类型: array 默认值: []

The content of the label option is translated before displaying it, so it can contain translation placeholders. This option defines the values used to replace those placeholders.

给定此翻译消息

1
2
# translations/messages.en.yaml
form.order.reset: 'Reset an order to %company%'

您可以按如下方式指定占位符值

1
2
3
4
5
6
7
8
9
use Symfony\Component\Form\Extension\Core\Type\ResetType;
// ...

$builder->add('send', ResetType::class, [
    'label' => 'form.order.reset',
    'label_translation_parameters' => [
        '%company%' => 'ACME Inc.',
    ],
]);

按钮的 label_translation_parameters 选项与其父选项的相同选项合并,因此按钮可以重用和/或覆盖任何父占位符。

attr_translation_parameters

类型: array 默认值: []

The content of the title and placeholder values defined in the attr option is translated before displaying it, so it can contain translation placeholders. This option defines the values used to replace those placeholders.

给定此翻译消息

1
2
3
# translations/messages.en.yaml
form.order.id.placeholder: 'Enter unique identifier of the order to %company%'
form.order.id.title: 'This will be the reference in communications with %company%'

您可以按如下方式指定占位符值

1
2
3
4
5
6
7
8
9
$builder->add('id', null, [
    'attr' => [
        'placeholder' => 'form.order.id.placeholder',
        'title' => 'form.order.id.title',
    ],
    'attr_translation_parameters' => [
        '%company%' => 'ACME Inc.',
    ],
]);

子字段的 attr_translation_parameters 选项与其父字段的相同选项合并,因此子字段可以重用和/或覆盖任何父占位符。

row_attr

类型: array 默认值: []

添加到用于渲染表单类型行的元素的 HTML 属性的关联数组

1
2
3
$builder->add('body', TextareaType::class, [
    'row_attr' => ['class' => 'text-editor', 'id' => '...'],
]);

另请参阅

如果您想将这些属性添加到表单类型小部件元素,请使用 attr 选项。

本作品,包括代码示例,根据 Creative Commons BY-SA 3.0 许可协议获得许可。
目录
    版本