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.

Issue fork drupal-2671202

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

marcvangend created an issue. See original summary.

wim leers’s picture

Component: edit.module » quickedit.module
marcvangend’s picture

Issue summary: View changes
StatusFileSize
new401 bytes
new45.32 KB
new50.63 KB
new47.73 KB

As 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.

wim leers’s picture

Title: Field label is duplicated in the field value when using Quick Edit » Plain text field's label is duplicated in the value when edited & saved using Quick Edit

This doesn't happen when using formatted text, because then the original (unfiltered/unformatted) text is retrieved from the server.

wim leers’s picture

Title: Plain text field's label is duplicated in the value when edited & saved using Quick Edit » [regression] Plain text field's label is duplicated in the value when edited & saved using Quick Edit
Related issues: +#2559955: Ensure that Quick Edit relies less on the structure of the HTML
davidhernandez’s picture

Is this only happening with long text fields, or just fields with labels above?

wim leers’s picture

Issue summary: View changes
StatusFileSize
new60.52 KB

So #2559955: Ensure that Quick Edit relies less on the structure of the HTML changed this:

var $fieldItems = this.$el.find('.field__item');

to:

var $fieldItems = this.$el.find('.quickedit-field');

Now if we look at the HTML structure, then it totally makes sense why the bug reported in this issue is happening:

wim leers’s picture

Title: [regression] Plain text field's label is duplicated in the value when edited & saved using Quick Edit » [regression] Text field's label is duplicated in the value when edited & saved using Quick Edit

#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_REVERSIBLE or \Drupal\filter\Plugin\FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE.

davidhernandez’s picture

I 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.

wim leers’s picture

#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.

davidhernandez’s picture

I 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.

davidhernandez’s picture

Doesn'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.

wim leers’s picture

#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.

snehamay’s picture

Assigned: Unassigned » snehamay
Issue tags: +drupalconasia2016

I just perform round of testing and able to replicate the same thing. I am taking this under my assignment and provide the update ASAP.

chr.fritsch’s picture

Version: 8.0.3 » 8.1.x-dev
Assigned: snehamay » Unassigned
Issue tags: -drupalconasia2016

This is still an open issue

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

yoroy’s picture

Just 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.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

redgluten’s picture

StatusFileSize
new2.33 KB

This 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.

redgluten’s picture

Edit: 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.

redgluten’s picture

My 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.

redgluten’s picture

So 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?

szeidler’s picture

I 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.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

rfsbsb’s picture

StatusFileSize
new1.54 KB

Re-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.

greggles’s picture

Version: 8.6.x-dev » 8.7.x-dev
Status: Active » Needs review

I just ran into this issue, so updating the version to 8.7.x.

greggles’s picture

Status: Needs review » Needs work

I tested this on a site using Bartik and it didn't seem to fix the issue.

szeidler’s picture

Bartik for example uses the class field__label for the field label. For this reason #27 seems to fail on Bartik.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.9 was released on November 6 and is the final full bugfix release for the Drupal 8.7.x series. Drupal 8.7.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.8.0 on December 4, 2019. (Drupal 8.8.0-beta1 is available for testing.)

Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

vdsh’s picture

We have the same issue with ckeditor fields - with the following in core/modules/ckeditor/js/ckeditor.js:

element.setAttribute('contentEditable', 'true');
return !!CKEDITOR.inline(element, settings);

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.

vrwired’s picture

StatusFileSize
new1.54 KB

There 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.

suresh prabhu parkala’s picture

Status: Needs work » Needs review
StatusFileSize
new1.71 KB

Re-rolled patch. please review.

u_tiwari made their first commit to this issue’s fork.

gauravvvv’s picture

StatusFileSize
new1.54 KB
new837 bytes

Re-rolled patch #35. Attached interdiff for same.

chetanbharambe’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new334.05 KB
new327.39 KB

Hi @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.

lauriii’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

I think we should still add test coverage to make sure that this regression doesn't happen again.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev
spokje’s picture

Project: Drupal core » Quick Edit
Version: 9.3.x-dev » 1.0.x-dev
Component: quickedit.module » Code

Due to Quickedit being moved out of Drupal Core and into a Contrib Module, moving this issue to the Contrib Module queue.

liquidcms’s picture

Just 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.

ckaotik’s picture

Status: Needs work » Needs review
StatusFileSize
new8.91 KB

I've added a test case for this and hope it makes sense. My approach is a bit different, I look for the .field__label class (instead of both .field__label and .field__item) and add contenteditable="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__label class to your templates.

ckaotik’s picture

Follow-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".

ckaotik’s picture

StatusFileSize
new9.39 KB
new1.55 KB

Fix whitespace, thanks text editor... Also added an interdiff.