The submit button is not following any condition while in popup/dialogs

Created on 21 October 2018, about 6 years ago
Updated 25 June 2024, 6 months ago

Hi,

Description of the issue
The form button like the default "Submit" button of any webform , is not accepting any #state conditions once the dialog is initialized.

Problem
The problem is in getting the default state of the button to initialize in the dialog. Because once you start entering input values the button's state is updated.

Why
The issue is Drupal.behaviors.dialog.prepareDialogButtons in core/misc/dialog/dialog.ajax.es6.js clones the primary buttons without copying the #states conditions.

This must be a core States API issue.

Reproduce the issue:

1) Install the webform module.

2) Using the built-in "contact" form, create a condition to hide the "Send message" button.

_ "Hidden" if "Your Name" textfield value is "Hide Button".

the yaml #state condition will be something like:

  '#states':
    invisible:
      ':input[name="name"]':
        value: 'Hide Button'

3) Add the "contact" form as a field of type "webform" to the article content type.

4) Create one test article, lets consider the article nid is "12".

5) launch the created article in a dialog/popup using the below code:

<a class="use-ajax" data-dialog-type="modal" href="/node/12">Open article</a>

6) Find the webform field and try to input inside the "your name" field the text: Hide Button

7) You will notice that the "Send message" button is still visible without any changes for its #states.

Reference
The discussion of the webform issue here , lead to create this core issue.

Thank you all for your help and time,

Below is the source code of a configured "contact" form to speed up the reproducing of the issue:

name:
  '#type': textfield
  '#title': 'Your Name'
  '#required': true
  '#default_value': '[current-user:account-name]'
  '#multiple__no_items_message': '<p>No items entered. Please add items below.</p>'
email:
  '#title': 'Your Email'
  '#type': email
  '#required': true
  '#default_value': '[current-user:mail]'
subject:
  '#type': textfield
  '#title': Subject
  '#required': true
  '#states':
    visible:
      ':input[name="name"]':
        value: Webform
  '#multiple__no_items_message': '<p>No items entered. Please add items below.</p>'
  '#test': 'Testing contact webform from [site:name]'
message:
  '#title': Message
  '#type': textarea
  '#required': true
  '#test': 'Please ignore this email.'
actions:
  '#type': webform_actions
  '#title': 'Submit button(s)'
  '#states':
    invisible:
      ':input[name="name"]':
        value: 'Hide Button'
  '#states_clear': false
  '#submit__label': 'Send message'
🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Ajax 

Last updated 2 days ago

Created by

🇱🇧Lebanon C.E.A

Live updates comments and jobs are added and updated live.
  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024