nswdpc/silverstripe-details-field

复合表单字段,以HTML details标签的形式渲染,包含子字段

安装次数: 362

依赖关系: 0

建议者: 0

安全: 0

星标: 1

关注者: 1

分支: 0

公开问题: 0

类型:silverstripe-vendormodule

v1.0.0 2024-05-14 02:27 UTC

This package is auto-updated.

Last update: 2024-09-14 03:08:27 UTC


README

本模块使用HTML Details元素实现了Silverstripe的FormField。

该字段是一个CompositeField,允许在元素处于打开状态时显示零个或多个子字段。

对于包含长选择字段和/或非必需信息(在表单提交中不需要)非常有用。

使用方法

在模块安装后,在代码中使用DetailsField

添加子字段

<?php
namespace MyApp;

use NSWDPC\Forms\DetailsField\DetailsField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;

// ... etc

$childFields = FieldList::create(
    TextField::create('Salutation', _t('myapp.SALUTATION','Salutation')),
    TextField::create('FirstName', _t('myapp.FIRST_NAME','First name')),
    TextField::create('Surname', _t('myapp.SURNAME','Surname'))
);

$detailsField = DetailsField::create($childFields)
    ->setTitle(
        _t(
            'myapp.PROVIDE_DETAILS',
            'Provide some optional information'
        )
    )->setDescription(
        _t(
            'myapp.PROVIDE_DETAILS_DESCRIPTION',
            'A field description'
        )
    );
    
// by default the element is in a closed state, to open by default (or when values are present in the child fields)
// $detailsField = $detailsField->setIsOpen(true)

// push onto form fields
$fields->push($detailsField);
// ... etc

更多内容请参考tests/DetailsFieldTest。

示例渲染字段

提供一些可选信息

字段描述

问候语 [___________] 名字 [___________] 姓氏 [___________]

额外功能

  • setTitlesetSummary方法的别名,两者都用于设置字段的title属性值
  • 您可以为FormField设置标准描述、右标题和字段验证消息
  • IsOpenSummary返回那些属性值,用于模板中
  • 由于<summary>元素可以包含某些HTML,您可以将DBHTMLVarchar字段作为值提供给setTitle或setSummary
  • 如果字段或子字段有验证消息,默认情况下细节元素将是打开的

安装

composer require nswdpc/silverstripe-details-field

许可证

BSD-3-Clause

维护者

错误跟踪器

我们欢迎您在GitHub Issue tracker上为这个项目提交错误报告、拉取请求和特性请求。

在提交新问题之前,请查阅行为准则

安全

如果您发现这个模块存在安全问题,请首先通过电子邮件digital[@]dpc.nsw.gov.au详细说明您发现的情况。

开发和贡献

如果您想为模块做出贡献,请确保提出拉取请求并与模块维护者进行讨论。

在完成拉取请求之前,请查阅行为准则