inspiredminds/contao-fieldset-duplication

Contao 扩展,允许用户在前端复制表单字段集,以添加更多输入字段。

资助包维护!
fritzmg

安装次数: 5,406

依赖关系: 1

建议者: 0

安全: 0

星级: 13

关注者: 4

分支: 6

开放问题: 7

类型:contao-bundle

2.2.0 2024-04-02 09:00 UTC

README

Contao Fieldset Duplication

Contao 扩展,允许用户在前端复制表单字段集,以添加更多输入字段。

Example screenshot of the front end

您需要在您的页面布局中启用 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: '&times;',
        /* 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 字符串