Problem/Motivation
When using the Quick Edit function on a text field with a field label above it, the field label is inserted in the field value.
Steps to reproduce
1. Clean install, standard profile
2. Add a field "Summary" (long text, plain) to the Article content type
3. Create a new Article node and go to that page
4. Click the pencil icon on the node content and choose "Quick edit"
5. Click the summary field (Notice how the Field label becomes editable too), make a change, and click "Save"
6. Notice that the field label has been duplicated in the field content: the field content now starts with "Summary"
Proposed resolution
t.b.d.
Remaining tasks
t.b.d.
User interface changes
Probably none.
API changes
Probably none.
Data model changes
Probably none.
| Comment | File | Size | Author |
|---|---|---|---|
| #47 | interdiff-45-47.txt | 1.55 KB | ckaotik |
| #47 | quickedit-field_label_duplicated_in_value-2671202-47.patch | 9.39 KB | ckaotik |
| #45 | quickedit-field_label_duplicated_in_value-2671202-45.patch | 8.91 KB | ckaotik |
| #39 | After Patch 2671202.png | 327.39 KB | chetanbharambe |
| #39 | Before Patch 2671202.png | 334.05 KB | chetanbharambe |
Issue fork drupal-2671202
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
wim leersComment #3
marcvangendAs requested, I'm including screenshots (before, while editing, and after) and an export of the field configuration.
PS. Note that "Summary" is just an example field name here, this has nothing to do with the text-with-summary type of text fields. The problem occurs with other field names too.
Comment #4
wim leersThis doesn't happen when using formatted text, because then the original (unfiltered/unformatted) text is retrieved from the server.
Comment #5
wim leersThis is a regression caused by #2559955: Ensure that Quick Edit relies less on the structure of the HTML.
Comment #6
davidhernandezIs this only happening with long text fields, or just fields with labels above?
Comment #7
wim leersSo #2559955: Ensure that Quick Edit relies less on the structure of the HTML changed this:
to:
Now if we look at the HTML structure, then it totally makes sense why the bug reported in this issue is happening:
Comment #8
wim leers#6: just with text fields in general. I'm pretty sure this also happens with non-long text fields.
In fact, I retract #4, because this should also happen for formatted text fields as long as they don't use any filters of the types
\Drupal\filter\Plugin\FilterInterface::TYPE_TRANSFORM_REVERSIBLEor\Drupal\filter\Plugin\FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE.Comment #9
davidhernandezI just tried this with a "Text (formatted, long, with summary)", "Text (formatted)", and "Text (plain, long)". It only happens with the plain text field. Not sure why, when structurally they all appear to be the same. I'm not seeing any difference between them in the markup.
Comment #10
wim leers#9: see the bottom part in #4. Try it with a text format that doesn't have any filters. Then you should be able to reproduce it there too.
Comment #11
davidhernandezI tried with a new text format, with no filters. I cannot reproduce. I either get the hovering toolbar, or the popup with the field data and the select box for choosing a different text format. The plain text field is the only one that edits directly in page and grabs the label. I'm going to try with other field types.
Comment #12
davidhernandezDoesn't work with a number field, probably for obvious reasons. It has that increase/decrease value widget. But it did work with an email field, which also does not use a text format.
Comment #13
wim leers#11: Hm, I'll need to check why that is then. Thanks for testing that!
#12: It can only ever be the plain & rich text fields, because those are the ones that have custom in-place editors. Everything else falls back to the form-based in-place editor, and so it couldn't possibly happen there, because forms don't use
contenteditable.Comment #14
snehamay commentedI just perform round of testing and able to replicate the same thing. I am taking this under my assignment and provide the update ASAP.
Comment #15
chr.fritschThis is still an open issue
Comment #18
yoroy commentedJust ran into this. When deleting the value text you can also delete the label. It then saves the label as the value. Very weird to see that happening.
Comment #20
redgluten commentedThis patch fixes the issue by keeping the `textElement` variable to scope the whole field (presumably for managing the interaction?) but only storing the text value of the `.content-field` child.
Comment #21
redgluten commentedEdit: the previous fix was missing some places where the DOM selector needed to be updated. I submit here an updated patch for 8.4.x as well as a patch for 8.3.x.
A nicer patch would probably create a new property to store the actual content field separately from the field wrapper but I’m not familiar enough with the core conventions to propose something properly named.
Comment #22
redgluten commentedMy bad, please disregard the previous patches for the moment: they assume the presence of CSS classes that are not part of the stable theme. I’ll update my patches later to reflect this.
Comment #23
redgluten commentedSo here’s an actual working patch tested on the latest 8.4 dev branch. Again the coding style is probably not the best but as this actually works, I hope some core maintainer can improve on it and merge that for an 8.4.x release?
Comment #24
szeidler commentedI can confirm #23 is solving the issue for classy themes, but the problem is that we start running in circles. The error was introduced in #2559955: Ensure that Quick Edit relies less on the structure of the HTML and the patch more or less is reverting it.
Comment #27
rfsbsbRe-rolling this patch to work on newer Drupal versions.
Even though I understand it's not desirable to have specific markup on this, I guess this patched version will work by default with both scenarios (either having labels or not) with most websites that uses Drupal default structure.
Comment #28
gregglesI just ran into this issue, so updating the version to 8.7.x.
Comment #29
gregglesI tested this on a site using Bartik and it didn't seem to fix the issue.
Comment #30
szeidler commentedBartik for example uses the class
field__labelfor the field label. For this reason #27 seems to fail on Bartik.Comment #33
vdsh commentedWe have the same issue with ckeditor fields - with the following in core/modules/ckeditor/js/ckeditor.js:
I tried to apply the same reasonning as in the patch - but then it messed everything up.
Additionnally, bootstrap barrio is also using field__label - so this doesn't seem the right approach to the issue.
Comment #34
vrwired commentedThere should probably be a config setting for the class name (re: #30). This patch is an alternative to #27 where replaces dashes with underscore specific to using a theme set up for this format.
Comment #35
suresh prabhu parkala commentedRe-rolled patch. please review.
Comment #38
gauravvvv commentedRe-rolled patch #35. Attached interdiff for same.
Comment #39
chetanbharambe commentedHi @Gauravmahlawat
Thanks for the patch.
Verified and tested patch #38.
Patch applied successfully and looks good to me.
Testing Steps:
# Goto: Appearance -> Apply Seven theme
# Add a field "Summary" (long text, plain) to the Article content type
# Create a new Article node and go to that page
# Click the pencil icon on the node content and choose "Quick edit"
# Click the summary field (Notice how the Field label becomes editable too), make a change, and click "Save"
# Notice that the field label has been duplicated in the field content: the field content now starts with "Summary"
Expected Results:
# After applying the patch, the Field label should not appear as a duplicate.
Actual Results:
# Currently, the field label has been duplicated in the field content: the field content now starts with "Summary"
Please refer attached screenshots for the same.
Looks good to me.
Can be a move to RTBC.
Comment #40
lauriiiI think we should still add test coverage to make sure that this regression doesn't happen again.
Comment #43
spokjeDue to Quickedit being moved out of Drupal Core and into a Contrib Module, moving this issue to the Contrib Module queue.
Comment #44
liquidcms commentedJust tested patch from #38 on site with 9.2.11:
- patch applies but doesnt work.
Theme is bootstrap based. I am using Simpler Quickedit module (as without it i can't get QE to work on user fields). And this is on a user plain text field with the label Above the field. When the label is inline, as soon as i edit the label is embedded into the edit area. So i guess technically i could remove it and then when i save it isnt re-added (like with label set as Above); but obviously not the right answer.
Comment #45
ckaotikI've added a test case for this and hope it makes sense. My approach is a bit different, I look for the
.field__labelclass (instead of both.field__labeland.field__item) and addcontenteditable="false"to those. If such a label was found, the user cannot edit it, to hopefully prevent some confusion. Label contents are stripped from the saved value. If there's no dedicated label, everything stays the same as before.The general problem is that we need some way to figure out what's the label and what's the actual value we want edited. This is however highly dependent on the theme :( So for now, you'd need to add that
field__labelclass to your templates.Comment #46
ckaotikFollow-up patch that fixes restoring the original field after changes were made and discarded.
We should probably also add tests for "the label is displayed as expected after discarding changes".
Comment #47
ckaotikFix whitespace, thanks text editor... Also added an interdiff.