inspiredminds / contao-fieldset-duplication
Contao 扩展,允许用户在前端复制表单字段集,以添加更多输入字段。
2.2.0
2024-04-02 09:00 UTC
Requires
- php: >=7.4
- ext-json: *
- composer/semver: ^1.0 || ^2.0 || ^3.0
- contao/core-bundle: ^4.9 || ^5.0
- doctrine/dbal: ^2.11 || ^3.0
- jean85/pretty-package-versions: ^1.0 || ^2.0
- mvo/contao-group-widget: ^1.3
- symfony/polyfill-php80: ^1.29
- symfony/service-contracts: ^1.0 || ^2.0 || ^3.0
Requires (Dev)
- contao/manager-plugin: ^2.0
- friendsofphp/php-cs-fixer: ^3.0
- terminal42/contao-leads: ^1.4 || ^3.0
- terminal42/contao-mp_forms: ^4.4
README
Contao Fieldset Duplication
Contao 扩展,允许用户在前端复制表单字段集,以添加更多输入字段。
您需要在您的页面布局中启用 js_fieldset_duplication
模板。以下选项可以更改
<?= Contao\Template::generateScriptTag('bundles/contaofieldsetduplication/js.fieldset.duplication.min.js', false, null) ?> <script> document.addEventListener('DOMContentLoaded', function() { var elements = document.querySelectorAll('fieldset.allow-duplication'); elements.forEach(function(element) { fieldsetDuplication(element, { /* when true, prepends the button wrapper within the fieldset, instead of appending */ prepend: false, /* text content of the add button */ buttonAdd: '+', /* text content of the remove button */ buttonRemove: '×', /* a custom widget CSS selector */ widgetSelector: '.form-widget', // defaults to .widget }); }); }); </script>
如果您想将额外的数据存储在您的数据库表中(使用表单生成器将数据存储在数据库中的能力),您需要将名为 fieldset_duplicates
的列添加到您的目标表中。然后,此列将包含以 JSON 编码对象形式提交的附加字段。
注意:版本 2.1.0
引入了 js_fieldset_duplication
模板。为了向后兼容,此扩展的前几个版本中还有一个名为 j_fieldset_duplication
的 jQuery 版本。请确保 不要 启用这两个模板。
通知令牌
如果您需要将字段集渲染为通知令牌,您可以定义通知令牌格式。只需定义字段集名称、格式名称并选择一个模板。字段集将在令牌 form_{NAME}_{FORMAT}
(如果您不使用通知中心,则为 {NAME}_{FORMAT}
)下可用。
此扩展附带以下模板
- nc_fieldset_duplication_text:将字段集数据渲染为
label: value
对 - nc_fieldset_duplication_html:将字段集数据渲染为 HTML 表格
- nc_fieldset_duplication_json:将字段集数据渲染为 JSON 字符串