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
- In a vanilla Drupal install with Webform, apply this form definition
- Open the form
- Click 'show'
- Notice the text area is shown without wysiwyg editor
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
Additional:
- Change the default value of the radios to 'show'
- Refresh the form
- Notice the wysiwyg editor is present.
| Comment | File | Size | Author |
|---|---|---|---|
| #12 | 3193365-12.patch | 1.72 KB | jrockowitz |
| #10 | 3193365-10.patch | 576 bytes | jrockowitz |
Issue fork webform-3193365
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
Comment #2
sutharsan commentedCan be reproduced in 6.0.0 too.
Comment #3
jrockowitz commentedI 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.
Comment #4
sutharsan commentedI 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.
Comment #5
sutharsan commentedI tracked it down to
clearValueAndRequiredin webform.states.js. One of the input fields it is called upon is theformatted_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.
Comment #7
sutharsan commentedComment #8
sutharsan commentedComment #9
jrockowitz commentedNot 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.
Comment #10
jrockowitz commentedComment #12
jrockowitz commentedComment #13
sutharsan commentedLess 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.
Comment #15
jrockowitz commented