shane310/field_group_ajaxified_multipage

允许将字段组用于构建多页面内容创建表单。

dev-master 2021-07-23 07:26 UTC

This package is auto-updated.

Last update: 2024-09-23 14:34:36 UTC


README

  • 简介
  • 要求
  • 安装
  • 配置
  • 使用自定义表单
  • 问题
  • 维护者

介绍

Field Group Ajaxified Multipage 模块使得将表单转换为使用组的多页面表单成为可能。

它还向开发者提供了与表单数组相关的特殊变量,用于页面状态,以便他们可以根据活动页面进一步自定义表单。

此外,它适用于任何表单,甚至是自定义表单!

要求

  • 字段组

    使用字段组,可以轻松将实体表单转换为多页面表单。

安装

  • 使用 "composer require 'drupal/field_group_ajaxified_multipage:'" 安装 Field Group Ajaxified Multipage 模块,然后启用该模块。

配置 - 使用字段组

1. You'll have two new types of field groups on the displays:

    - Multipage step: Use this type of group to wrapper each field of your
    step.

    - Multipage group: Use this type of group to wrapper each step group
    "Multipage step".
    The options than able the multipage works properly are:
        * Ajaxfied: Yes.
        * Non Javascript Multistep: No.

使用自定义表单

字段组ajaxified multipage 允许将自定义表单转换为多页面ajax表单。

包含一个子模块 "fgam_example",其中包含自定义表单的完整示例。启用模块后,您可以在 "examples/field_group_ajaxified_multipage/custom_form" 中查看结果。

代码在 Example.php 文件中。

如果您是开发者并且想实现更复杂的多页面表单,可以使用模块定义的以下变量

* "$form_state['field_group_ajaxified_multipage_enabled']" This is sets when

表单多页定义。

* "$form_state['field_group_ajaxified_multipage_group']" This  contains the

多页组。

使用这些变量的示例代码

function hook_form_alter(&$form, &$form_state, $form_id) {

    if (isset($form_state['field_group_ajaxified_multipage_enabled']) &&
        $form_state['field_group_ajaxified_multipage_enabled']) {

        // Actual number step.
        $step = empty($form_state['storage']['field_group_ajaxified_multipage_step']) ? 1 : $form_state['storage']['field_group_ajaxified_multipage_step'];

        // Main group multipage.
        $page_group = $form_state['field_group_ajaxified_multipage_group'];

        // Best practice for accessing variables, it works even when this ajax
        // grouping is disabled.
        if (isset($form_state['storage']['all']['values'])) {
          $values = $form_state['storage']['all']['values'];
        }
        elseif (isset($form_state['values'])) {
          $values = $form_state['values'];
        }

    }
}

问题

分页只能在客户端进行,这有几个缺点。

1. Validation of form fields is very basic, real validation is done after
   the form is submitted and users will often have to return to previous
   pages to correct the entered values.
2. More complex multi page forms often dynamically change what the users see
   in next steps depending on the data entered in previous steps. Now that
   the form pages are Ajaxified, there are no limitations.
3. When the form is complex and has many pages with different fields, it
   can become considerably heavy to load since it uses javascript to
   hide/show related fields on each page, but the whole form is still
   loaded.

默认情况下不支持 FORM API 图像按钮。

维护者

支持组织