Problem/Motivation

When a Text format which is hidden by default, is made visible, the wysiwyg button bar is missing.

With the same fields (as below) created with code in a normal Drupal form, the wysiwyg editor does get applied.

Steps to reproduce

  1. In a vanilla Drupal install with Webform, apply this form definition
  2. hide_or_show:
      '#type': radios
      '#title': 'Hide or show'
      '#options':
        hide: hide
        show: show
      '#default_value': hide
    formatted_text:
      '#type': text_format
      '#title': 'Formatted text'
      '#states':
        invisible:
          ':input[name="hide_or_show"]':
            value: hide
      '#allowed_formats':
        filtered_html: filtered_html
    
  3. Open the form
  4. Click 'show'
  5. Notice the text area is shown without wysiwyg editor

Additional:

  • Change the default value of the radios to 'show'
  • Refresh the form
  • Notice the wysiwyg editor is present.
CommentFileSizeAuthor
#12 3193365-12.patch1.72 KBjrockowitz
#10 3193365-10.patch576 bytesjrockowitz

Issue fork webform-3193365

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Sutharsan created an issue. See original summary.

sutharsan’s picture

Can be reproduced in 6.0.0 too.

jrockowitz’s picture

Status: Active » Postponed (maintainer needs more info)

I think this issue is coming from Drupal core.

@see #997826: #states doesn't work correctly with type text_format

Please test the recommended patch and see if it resolves this issue.

sutharsan’s picture

Status: Postponed (maintainer needs more info) » Active

I have tried the patch with on core 9.1.2 (with webform 6.0) and on core 8.9.11 (manual patch; with webform 8.x-5.19), but it does not fix the problem. I also applied the work around suggested in the issue by wrapping the editor a container but also no luck. I therefore think we have a different issue here.

sutharsan’s picture

I tracked it down to clearValueAndRequired in webform.states.js. One of the input fields it is called upon is the formatted_text[format] input field. Without a format, the editor no longer works. We should not clear this field since because the user can never restore its value.

The easiest approach I found is to not clear the value of hidden fields.

sutharsan’s picture

Title: Text format field without wysiwyg » 3193365-hidden-value
Status: Active » Needs review
sutharsan’s picture

Title: 3193365-hidden-value » Text format field without wysiwyg
jrockowitz’s picture

Status: Needs review » Needs work

Not clearing the value of hidden fields could cause unexpected regressions.

It would be safer to specifically not clear hidden inputs for text formats.

BTW, thanks for figuring out the source of the problem.

jrockowitz’s picture

Status: Needs work » Needs review
StatusFileSize
new576 bytes

Status: Needs review » Needs work

The last submitted patch, 10: 3193365-10.patch, failed testing. View results

jrockowitz’s picture

Status: Needs work » Needs review
StatusFileSize
new1.72 KB
sutharsan’s picture

Status: Needs review » Reviewed & tested by the community

Less is more :) This is indeed the better solution.

Tested the patch and it works. It also fixes the (hypothetical) case that multiple text formats are presented in a select list.

  • jrockowitz authored 66ff21f on 8.x-5.x
    Issue #3193365 by Sutharsan, jrockowitz: Text format field without...
jrockowitz’s picture

Status: Reviewed & tested by the community » Fixed

  • jrockowitz authored 66ff21f on 6.x
    Issue #3193365 by Sutharsan, jrockowitz: Text format field without...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.