Issue #2346773 by dmsmidt, lokapujya, klakegg, marcvangend, andrewmacpherson, ptsimard, Getekid, Rade, yoroy, tstoeckler, mgifford, tim.plunkett, estoyausente, xjm, PierreMarcel, hass, SKAUGHT, sukanya.ramakrishnan, flyke, alvar0hurtad0, bojanz, pwolanin, arunkumark, Bojhan, bleen: Details form element should open when there are errors on child elements
parent
01ac7634be
commit
bfdfe82ea2
|
@ -75,7 +75,9 @@ class Details extends RenderElement {
|
|||
|
||||
// Collapsible details.
|
||||
$element['#attached']['library'][] = 'core/drupal.collapse';
|
||||
if (!empty($element['#open'])) {
|
||||
|
||||
// Open the detail if specified or if a child has an error.
|
||||
if (!empty($element['#open']) || !empty($element['#children_errors'])) {
|
||||
$element['#attributes']['open'] = 'open';
|
||||
}
|
||||
|
||||
|
|
|
@ -115,6 +115,21 @@ class NodeEditFormTest extends NodeTestBase {
|
|||
// Check if the node revision checkbox is rendered on node edit form.
|
||||
$this->drupalGet('node/' . $node->id() . '/edit');
|
||||
$this->assertFieldById('edit-revision', NULL, 'The revision field is present.');
|
||||
|
||||
// Check that details form element opens when there are errors on child
|
||||
// elements.
|
||||
$this->drupalGet('node/' . $node->id() . '/edit');
|
||||
$edit = [];
|
||||
// This invalid date will trigger an error.
|
||||
$edit['created[0][value][date]'] = $this->randomMachineName(8);
|
||||
// Get the current amount of open details elements.
|
||||
$open_details_elements = count($this->cssSelect('details[open="open"]'));
|
||||
$this->drupalPostForm(NULL, $edit, t('Save and keep published'));
|
||||
// The node author details must be open.
|
||||
$this->assertRaw('<details class="node-form-author js-form-wrapper form-wrapper" data-drupal-selector="edit-author" id="edit-author" open="open">');
|
||||
// Only one extra details element should now be open.
|
||||
$open_details_elements++;
|
||||
$this->assertEqual(count($this->cssSelect('details[open="open"]')), $open_details_elements, 'Exactly one extra open <details> element found.');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue