Skip to content
Snippets Groups Projects
Commit 9111e803 authored by catch's avatar catch
Browse files

Issue #822128 by roborn, JamesK, nod_: Fixed 'Textarea + summary' widget...

Issue #822128 by roborn, JamesK, nod_: Fixed 'Textarea + summary' widget broken when field allows multiple values.
parent 3278b19d
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -6,41 +6,41 @@
Drupal.behaviors.textSummary = {
attach: function (context, settings) {
$(context).find('.text-summary').once('text-summary', function () {
var $widget = $(this).closest('div.field-type-text-with-summary');
var $summaries = $widget.find('div.text-summary-wrapper');
var $widget = $(this).closest('.text-format-wrapper');
$summaries.once('text-summary-wrapper').each(function(index) {
var $summary = $(this);
var $summaryLabel = $summary.find('label');
var $full = $widget.find('.text-full').eq(index).closest('.form-item');
var $fullLabel = $full.find('label');
var $summary = $widget.find('.text-summary-wrapper');
var $summaryLabel = $summary.find('label');
var $full = $widget.find('.text-full').closest('.form-item');
var $fullLabel = $full.find('label');
// Create a placeholder label when the field cardinality is
// unlimited or greater than 1.
if ($fullLabel.length == 0) {
$fullLabel = $('<label></label>').prependTo($full);
}
// Setup the edit/hide summary link.
var $link = $('<span class="field-edit-link">(<a class="link-edit-summary" href="#">' + Drupal.t('Hide summary') + '</a>)</span>').toggle(
function () {
$summary.hide();
$(this).find('a').html(Drupal.t('Edit summary')).end().appendTo($fullLabel);
return false;
},
function () {
$summary.show();
$(this).find('a').html(Drupal.t('Hide summary')).end().appendTo($summaryLabel);
return false;
}
).appendTo($summaryLabel);
// Create a placeholder label when the field cardinality is greater
// than 1.
if ($fullLabel.length === 0) {
$fullLabel = $('<label></label>').prependTo($full);
}
// If no summary is set, hide the summary field.
if ($(this).find('.text-summary').val() == '') {
$link.click();
// Set up the edit/hide summary link.
var $link = $('<span class="field-edit-link">(<a class="link-edit-summary" href="#nogo">' + Drupal.t('Hide summary') + '</a>)</span>');
var $a = $link.find('a');
$link.toggle(
function (e) {
e.preventDefault();
$summary.hide();
$a.html(Drupal.t('Edit summary'));
$link.appendTo($fullLabel);
},
function (e) {
e.preventDefault();
$summary.show();
$a.html(Drupal.t('Hide summary'));
$link.appendTo($summaryLabel);
}
return;
});
).appendTo($summaryLabel);
// If no summary is set, hide the summary field.
if ($widget.find('.text-summary').val() === '') {
$link.click();
}
});
}
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment