Problem/Motivation
When implementing a required field of type webform_html_editor, the required field is not validated it contains data.
Current behavior:
A required webform_html_editor field can be saved without input.
Expected behavior:
A required webform_html_editor field produces an error message on webform save "The field Administrative description is required."
Steps to reproduce
Introduce a '#type' => 'webform_html_editor' where '#required' = TRUE:
$form['general_settings']['description'] = [
'#type' => 'webform_html_editor',
'#title' => $this->t('Administrative description'),
'#default_value' => $webform->get('description'),
'#required' => TRUE,
];
Save the webform:
Proposed resolution
It seems the magic in Drupal\webform\Element\WebformHtmlEditor::validateWebformHtmlEditor()
doesn't get executed when there are other errors in the settings form. This causes an array to be set for $element['#value']['value']
in preRenderWebformHtmlEditor()
.
Adding the code below to preRenderWebformHtmlEditor
seems to help, feels kind of wrong though. Don't know enough about the history of the webform_html_editor
form field type to provide an alternative? Any suggestions would be welcome.
if(is_array($element['#value']['value'])){
$element['#value']=$element['#value']['value'];
$element['#format']=$element['#value']['format'];
}
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#7 | 2941032-7.patch | 10.05 KB | jrockowitz |
| |||
#5 | webform.webform.issue_2941032.yml | 3.23 KB | jrockowitz |
#4 | type-webform_html_editor-required-validation.gif | 365.37 KB | idebr |
Comments
Comment #2
seanBCleaned the IS and title up a bit. This has nothing to do with the custom field as far as I could tell.
Comment #3
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedHave you tested the latest dev release.
I think this is a duplicate issue.
@see #2939788: Custom email body replaced with "Array" on validation error (disabled dialogs)
If this is not a duplicate issue, can you please provide the steps required to reproduce the problem.
Comment #4
idebr CreditAttribution: idebr at ezCompany commentedThe attached patch does not solve the problem.
I have expanded the issue summary with steps to reproduce.
Comment #5
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedThe attached webform can be used to reproduce the issue.
Comment #7
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedComment #8
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedI manually retested the patch and everything looks good. I committed the patch. Please download the latest dev release to review.