Problem/Motivation

When you have 2 or more text with summary fields and 1 has required summary but the others do not. The required summary is hidden.
The summary form element for the first text field is concealed and requires an additional "Edit Summary" click to reveal the summary form element.

Steps to reproduce

On a content type:
1. Create a "text with summary" field with summary input and required summary.
2. Create a second "text with summary" field with summary input. Do not require summary.
3. Attempt to create a new node.

Proposed resolution

The form should expose the summary form element for the first text field, and there should be no "Hide Summary" link.

From original posting
If I comment out line 41 of "text.js" ($link.trigger('click');), the summary element is not concealed but the "Hide Summary" link remains.

Inserting a simple logging statement (like console.log($(this));) before line 13 (var $widget = $(this).closest('.js-text-format-wrapper');) indicates that this code is getting executed for both fields.

A required class is added to the summary element, at least in my configuration. A simple fix is therefore to filter out required text summaries.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3145850

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

natedouglas created an issue. See original summary.

natedouglas’s picture

Version: 8.8.x-dev » 9.0.x-dev
StatusFileSize
new781 bytes

This appears to work without breaking my other content types.

natedouglas’s picture

Issue summary: View changes
Rkumar’s picture

Queueing for tests.
Meanwhile, let me try to replicate the scenario.

nod_’s picture

Version: 9.0.x-dev » 9.1.x-dev
Status: Active » Needs work

That's a good one, thanks. And you're correct about the fix.

I would check for the required attribute instead of the class.

+++ b/core/modules/text/text.js
@@ -8,7 +8,7 @@
+      $(context).find('.js-text-summary').not('.required').once('text-summary').each(function () {

I would use the required attribute and let the browser deal with evaluating the selector: .find('.js-text-summary:not([required])')

Also you edited the text.js file directly, have a look at the top of the file to see that we now use *.es6.js files for source: #2815083: Drupal core now using ES6 for JavaScript development

natedouglas’s picture

Ah, thanks. Sorry, I'm completely unfamiliar with how JS is processed in Drupal. And, apparently, can't read.

I think I did the interdiff right.

nod_’s picture

Status: Needs work » Needs review
Issue tags: +JavaScript, +Need tests
StatusFileSize
new1.14 KB

no worries. Was almost there :) you had the change in the right file and you needed to run yarn run build:js to update the text.js file. for interdiffs, it's better to name them .txt to make sure the testbot doesn't run them.

Provided the update text.js file.

But here we need tests to make sure we don't run into this later.

nod_’s picture

First pass at making a test

The last submitted patch, 8: core-js-summary-required-3145850-8--FAIL.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

pankaj.singh’s picture

Assigned: Unassigned » pankaj.singh
pankaj.singh’s picture

StatusFileSize
new63.55 KB
new64.83 KB
new49.03 KB
new54.35 KB
new43.88 KB
new56.53 KB

Tested the patch from #9 on 9.1.x. Patch worked for me as the form exposes the summary form element for the first text field, and there is no "Hide Summary" link for the Text1(marked required summary), as expected behavior.

Please refer to the attached screenshots with detailed insights. RTBC+1

pankaj.singh’s picture

Assigned: pankaj.singh » Unassigned
pankaj.singh’s picture

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

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

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

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

amateescu’s picture

Issue tags: -Need tests
StatusFileSize
new3.38 KB

I think it would be easier if we change the field widget to not output the js-text-summary class when the field is required.

I tested the patch from #8 first but it has a small problem, if a theme overrides text.js (like Bootstrap does), the fix in core's text.js is not carried over without an additional patch for that theme.

nod_’s picture

Needs to be confirmed btut we might still need to make the JS change to handle required status changes through JS #states API. (a non required issue summary becomes required after a change in another field).

gauravvvv’s picture

StatusFileSize
new3.38 KB
new647 bytes

Fixed MARKED SNIFF VIOLATIONS of patch #16, Attached interdiff for the same.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

s_leu’s picture

StatusFileSize
new3.16 KB

Patch doesn't apply anymore on 9.3.18, here's a re-roll.

pooja saraah’s picture

Tested the patch #21 patch applied successfully in drupal-9.5.x-dev.

pooja saraah’s picture

abhijith s’s picture

StatusFileSize
new37.04 KB
new23.66 KB

Applied patch #21 on 9.5.x and the required summary form element is exposed after this patch.

Before patch;
before

After patch:
after

smustgrave’s picture

Issue tags: +Bug Smash Initiative
StatusFileSize
new272.6 KB
new345.32 KB
new1.93 KB
new3.17 KB

Thank you for a super clear description and testing steps. Following those I was able to confirm the bug and with the patch confirm it's fixed.

This patch is the same as #21 but also uploading a tests-only patch for the person who will commit this.

The last submitted patch, 25: 3145850-25-tests-only.patch, failed testing. View results

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Looks like a good test

quietone’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs issue summary update

The issue summary does not have the standard template. Meaning there is no proposed resolution so reviewers can't confirm that the agreed to fix has been made. Adding tag.

Skimming the comments I see a question in #17 has not been answered. Setting to NW.

I also don't see a code review, my few comments below are not a full review.

  1. +++ b/core/modules/text/tests/src/FunctionalJavascript/TextareaWithSummaryTest.php
    @@ -100,4 +100,45 @@ public function testTextSummaryBehavior() {
    +    $page = $this->getSession()->getPage();
    +    $summary_field = $page->findField('edit-' . $field_name . '-0-summary');
    

    Looks like we can skip creating $page.

  2. +++ b/core/modules/text/tests/src/FunctionalJavascript/TextareaWithSummaryTest.php
    @@ -100,4 +100,45 @@ public function testTextSummaryBehavior() {
    +    $this->assertEquals(TRUE, $summary_field->isVisible(), 'Required summary is always shown.');
    

    Messages are no longer included is assertions.

smustgrave’s picture

Issue summary: View changes
smustgrave’s picture

Status: Needs work » Needs review
Issue tags: -Needs issue summary update
StatusFileSize
new800 bytes
new3.44 KB

Addressed #28

Took a look at #17 by
Hiding a text summary field until the title is filled in
When the field appeared it's summary was required
The default body field was not requiring summary.

So think we are good there.

Also updated issue summary so removing that tag.

deepalij’s picture

Assigned: Unassigned » deepalij
deepalij’s picture

Patch #30 failed to apply.
Re-roll the patch.

smustgrave’s picture

StatusFileSize
new0 bytes
new3.45 KB

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Passes 10.1 too

gaurav-mathur’s picture

Applied patch #33 works fine with expected results on Drupal 10.1.x-dev
Refer to the screenshot

jungle’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

#30 faild to apply, because of #3181778: [w/c September 17th] Replace t() with $this->t() in all plugins

interdiff-30-33.txt in #33 is empty. The following is supposed to be its content.

$ diff 3145850-30.patch 3145850-33.patch
2c2
< index 1dcb00b96b..1986fa120f 100644
---
> index 60b51650c8..3b1f541d7d 100644
6c6
<        '#title' => t('Summary'),
---
>        '#title' => $this->t('Summary'),
  • #36 tested it manually,
  • the test-only patch in #25 is still valid,
  • #28 was addressed.

Thanks!

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

kunal_sahu’s picture

Hi I have created an MR . Please Merge. thanks

smustgrave’s picture

@kunal_sahu thanks for the interest but the patch #33 was already reviewed. So the MR is just reuploading the work that was already done. So removing credit for that unless there was something you were fixing.

Thanks

gauravvvv’s picture

Updated attributions

larowlan’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: -JavaScript +JavaScript
+++ b/core/modules/text/tests/src/FunctionalJavascript/TextareaWithSummaryTest.php
@@ -94,10 +94,50 @@ public function testTextSummaryBehavior() {
+    $this->assertEquals(TRUE, $summary_field->isVisible(), 'Required summary is always shown.');

No need for the message here, as @quietone pointed out above in #28.

larowlan’s picture

Status: Needs work » Reviewed & tested by the community

On second thoughts, I can fix that on commit.

larowlan’s picture

Updating credits

  • larowlan committed f1fe67a8 on 10.0.x
    Issue #3145850 by smustgrave, natedouglas, nod_, Gauravvvv, s_leu,...

  • larowlan committed f908b84f on 10.1.x
    Issue #3145850 by smustgrave, natedouglas, nod_, Gauravvvv, s_leu,...

  • larowlan committed 7d195a3a on 9.5.x
    Issue #3145850 by smustgrave, natedouglas, nod_, Gauravvvv, s_leu,...
larowlan’s picture

Version: 10.1.x-dev » 9.5.x-dev
Status: Reviewed & tested by the community » Fixed

Fixed on commit

diff --git a/core/modules/text/tests/src/FunctionalJavascript/TextareaWithSummaryTest.php b/core/modules/text/tests/src/FunctionalJavascript/TextareaWithSummaryTest.php
index 75f6768dea9..0867f962c95 100644
--- a/core/modules/text/tests/src/FunctionalJavascript/TextareaWithSummaryTest.php
+++ b/core/modules/text/tests/src/FunctionalJavascript/TextareaWithSummaryTest.php
@@ -137,7 +137,7 @@ public function testTextSummaryRequiredBehavior() {
     $page = $this->getSession()->getPage();
     $summary_field = $page->findField('edit-' . $field_name . '-0-summary');
 
-    $this->assertEquals(TRUE, $summary_field->isVisible(), 'Required summary is always shown.');
+    $this->assertEquals(TRUE, $summary_field->isVisible());
   }
 
 }

Committed to 10.1.x and backported to 10.0.x and 9.5.x

Manually tested with a multi-cardinality field as there's some JS regarding that, but it need not run if the summary is optional - so all good.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.