Problem/Motivation
There was an issue: #1954968: Required CKEditor fields always fail HTML5 validation
"An invalid form control with name='{name}' is not focusable" JS error is thrown when a textarea has "required" attribute, but is not visible.
This was fixed in CKEditor: https://dev.ckeditor.com/ticket/8031
Now CKEditor removes the "required" attribute from textarea during initialization.
But the problem still exist if the "required" attribute is added via #states.
Steps to reproduce
Add states to node title and body field via form alter to make body field required when the node title is filled in.
Proposed resolution
Make this more reliable to handle if a field is changed to required via #states that the field gets marked as required and editors are notified when HTML5 validation fails,so that editors know what the problem is and can act on it.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #31 | 2722319-31.patch | 7.49 KB | kiseleva.t |
Issue fork drupal-2722319
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
leksat commentedHere is how I managed to fix the issue.
Comment #3
wim leersConditionally marking a field as required using
#statemakes no sense to me, because it means Form API (the server side) can't enforce it. What am I missing?Comment #4
wim leersAlso, this is minor at best, this is an extreme edge case that will at most affect 0.01%.
Comment #5
wim leersComment #6
leksat commentedYeah, I got this issue only because of custom modifications to the node edit form.
I'm not sure what's the process here, but I guess we can close this issue.
Current workaround: place the code from #2 to a custom module to solve the problem.
Comment #7
swirtThis is still an issue even though #1954968: Required CKEditor fields always fail HTML5 validation was already merged a long time ago. That solution did not account for a change of states.
I think there are two assumptions being made here.
Comment #8
mahdeI agree with swirt, I am facing this issue a lot with too many projects as well!
Comment #9
quietone commentedThis is reported on Drupal 8, which is no longer supported. Does this problem exist on a supported version of Drupal? If so, update the version value. Thanks
Comment #10
swirtYes this is still an issue in the D9. Can not say for certain on D10
Comment #11
aaron.ferris commentedIgnore me, this is a separate issue entirely
Comment #12
joevagyok commented@Wim Leers, here is the 0.01%! :)
We have many fields conditionally marked as required by states and having that enforced by symfony constraints on API level.
There are several contributed modules shipping custom fields with multiple subfields (columns) which might require different form logic on different projects by developers.
So I believe it is a real issue, just like others mentioned before me.
Comment #13
joevagyok commentedThe patch didn't work for me, and for some reason even when it worked, for some paragraph fields, the reinitialization placed an additional editor after the first one, so I ended up having 2 complete editors rendered for a single field.
So I tried to come up with a simple and clean solution to work around the problem, which basically keeps the editor's source element up to date via a listening to the change event inside the editor model. So when submit happens, the source element contains the data from the editor.
Pasting the JS code here:
Comment #14
wim leersOff-topic: I actually worked on something related a few weeks ago: #3409525: Regression from #3341682: #states + #required do not automatically work together, resulting in an unsubmittable AccountSettingsForm, but almost the opposite direction.
On-topic: let's start with writing a failing functional JS test that shows the problem, so that we can fix this and never regress again! 😊 Then the JS snippet in #13 should make that test pass. 👍
Comment #15
wim leersComment #17
joevagyok commentedPushed the test only to the MR which will fail.
Comment #18
joevagyok commentedPushed the fix which made the test pass.
Comment #19
joevagyok commentedComment #20
smustgrave commentedIssue summary appears incomplete. Please use the standard issue template.
Comment #21
swirtI just updated the summary to use the template.
Comment #22
joevagyok commentedComment #23
smustgrave commentedLeft 2 comments on MR, one is nitpicky but believe return docs should be included.
Comment #25
twilderanFix from related MR worked for me on Drupal core 10.2.2 and Conditional Fields 4.0.0-alpha5.
Needs review from community and we can include it in next release to fix this and related https://www.drupal.org/project/conditional_fields/issues/2988937
Comment #26
smustgrave commentedReading early comments I should of also tagged for steps to reproduce early on. It helps reviewers/committers to be able to quickly see how to reproduce the problem.
Comment #27
joevagyok commentedI updated the description to include the steps to reproduce.
The point of pushing test before the fix was to prove and show the problem, that should be the single source of truth for the reviewer, not what is in the issue description. But that is just my opinion.
Please see commits from #16.
Comment #28
smustgrave commentedPurpose of the issue summary is to be able to quickly get up to speed just fyi
Comment #29
smustgrave commentedIssue summary appears clear and all feedback on MR resolved.
Comment #30
nod_few comments
Comment #31
kiseleva.t commentedExported MR into patch file.
Comment #32
michaelsoetaertdeleted by user.