Tập tành tạo page in Webform Module với nhiều Step

29th May 2022
Table of contents

Question:

i've set up a very simple form to test out wizard page visibility. i cant seem to hide page 2 based on condition of fields in page 1.

set up and test

  • wizard page(1) has a checkbox(1) and a text field(1).
  • wizard page(2) has a text field(2).
  • page(1) text field condition = visible if checkbox(1) is checked.
  • test result: pass. toggles on and off with the checkbox(1).
  • wizard page(2) condition = visible if page(1) checkbox(1) is checked.
  • test result: fail(?). checking and unchecking checkbox(1) has no effect on page(2) visibility which remains visible regardless.

When i test the form it does skip page(2) if checkbox(1) is unchecked but the behaviour is more like enabled/disable than visible/hidden.

Example:

step_1:
  '#type': wizard_page
  '#title': 'Step 1'
  select_trigger:
    '#type': select
    '#title': 'Select Trigger'
    '#options':
      - Hide
      - Show
    '#required': true
step_2:
  '#type': wizard_page
  '#title': 'Step 2'
  flexbox_container:
    '#type': flexbox
    '#states':
      visible:
        ':input[name="select_trigger"]':
          value: Show
    radio:
      '#type': radios
      '#title': Radio
      '#options':
        'No': 'No'
        'Yes': 'Yes'
      '#required': true
    checkbox:
      '#type': checkboxes_other
      '#title': Checkbox
      '#options':
        one: One
        two: Two
        three: Three
      '#required': true
      '#states':
        visible:
          ':input[name="radio"]':
            '!value': 'No'
    textbox:
      '#type': textfield
      '#title': Textbox
      '#required': true
actions:
  '#type': webform_actions
  '#title': 'Submit button(s)'

Solution:

In the following example, a value from page 1 populates a computed token on page 2. and I will use computed token to make conditions in page 2.

Example:

step_1:
  '#type': wizard_page
  '#title': 'Step 1'
  select_trigger:
    '#type': select
    '#title': 'Select Trigger'
    '#options':
      - Hide
      - Show
    '#required': true
step_2:
  '#type': wizard_page
  '#title': 'Step 2'
  computed_select_trigger:
    '#type': computed_token
    '#display_on': form
    '#value': '[webform_submission:values:select_trigger]'
  flexbox_container:
    '#type': flexbox
    '#states':
      visible:
        ':input[name="computed_select_trigger"]':
          value: Show
    radio:
      '#type': radios
      '#title': Radio
      '#options':
        'No': 'No'
        'Yes': 'Yes'
      '#required': true
    checkbox:
      '#type': checkboxes_other
      '#title': Checkbox
      '#options':
        one: One
        two: Two
        three: Three
      '#required': true
      '#states':
        visible:
          ':input[name="radio"]':
            '!value': 'No'
    textbox:
      '#type': textfield
      '#title': Textbox
      '#required': true
actions:
  '#type': webform_actions
  '#title': 'Submit button(s)'
Bạn thấy bài viết này như thế nào?
0 reactions

Add new comment

Image CAPTCHA
Enter the characters shown in the image.
Câu nói tâm đắc: “Điều tuyệt với nhất trong cuộc sống là làm được những việc mà người khác tin là không thể!”

Related Articles

Master list (in progress) of how to get parts of fields for use in Twig templates. I’m always having to look these up, so I thought I’d hash them out and write them down.

Litespeed Cache là plugin WordPress dùng để kết hợp với Web Server LiteSpeed nhằm tăng tốc website WordPress của bạn gấp nhiều lần

In this article, we are going to see how some tools & libraries will make people's lives easier during the development & code review process.

In this tutorial, you will learn how to improve the custom code, theme and module, and general code development by using the pre-commit hook on git

Trước khi tìm hiểu xem PHP Code Sniffer là gì thì các bạn cần phải nắm được coding convention là gì đã.