Commit 33da0473 authored by Cottser's avatar Cottser

Issue #2708255 by dawehner, yoroy, swentel, Jacine, Gábor Hojtsy: Add support...

Issue #2708255 by dawehner, yoroy, swentel, Jacine, Gábor Hojtsy: Add support for #required on #type => details
parent 6316f212
......@@ -254,6 +254,7 @@ function template_preprocess_details(&$variables) {
$variables['description'] = (!empty($element['#description'])) ? $element['#description'] : '';
$variables['children'] = (isset($element['#children'])) ? $element['#children'] : '';
$variables['value'] = (isset($element['#value'])) ? $element['#value'] : '';
$variables['required'] = !empty($element['#required']) ? $element['#required'] : NULL;
// Suppress error messages.
$variables['errors'] = NULL;
......
......@@ -137,6 +137,20 @@ function testGroupElements() {
$this->assertTrue(count($elements) == 1);
}
/**
* Tests the #required property on details and fieldset elements.
*/
public function testRequiredFieldsetsAndDetails() {
$this->drupalGet('form-test/group-details');
$this->assertFalse($this->cssSelect('summary.form-required'));
$this->drupalGet('form-test/group-details/1');
$this->assertTrue($this->cssSelect('summary.form-required'));
$this->drupalGet('form-test/group-fieldset');
$this->assertFalse($this->cssSelect('span.form-required'));
$this->drupalGet('form-test/group-fieldset/1');
$this->assertTrue($this->cssSelect('span.form-required'));
}
/**
* Tests a form with a autocomplete setting..
*/
......
......@@ -17,8 +17,14 @@
*/
#}
<details{{ attributes }}>
{%
set summary_classes = [
required ? 'js-form-required',
required ? 'form-required',
]
%}
{%- if title -%}
<summary{{ summary_attributes }}>{{ title }}</summary>
<summary{{ summary_attributes.addClass(summary_classes) }}>{{ title }}</summary>
{%- endif -%}
{% if errors %}
......
......@@ -418,10 +418,11 @@ form_test.description_display:
_access: 'TRUE'
form_test.group_details:
path: '/form-test/group-details'
path: '/form-test/group-details/{required}'
defaults:
_form: '\Drupal\form_test\Form\FormTestGroupDetailsForm'
_title: 'Group details testing'
required: FALSE
requirements:
_access: 'TRUE'
......@@ -434,10 +435,11 @@ form_test.group_container:
_access: 'TRUE'
form_test.group_fieldset:
path: '/form-test/group-fieldset'
path: '/form-test/group-fieldset/{required}'
defaults:
_form: '\Drupal\form_test\Form\FormTestGroupFieldsetForm'
_title: 'Group fieldset testing'
required: FALSE
requirements:
_access: 'TRUE'
......
......@@ -20,11 +20,12 @@ public function getFormId() {
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
public function buildForm(array $form, FormStateInterface $form_state, $required = FALSE) {
$form['details'] = array(
'#type' => 'details',
'#title' => 'Root element',
'#open' => TRUE,
'#required' => !empty($required),
);
$form['meta'] = array(
'#type' => 'details',
......
......@@ -20,10 +20,11 @@ public function getFormId() {
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
public function buildForm(array $form, FormStateInterface $form_state, $required = FALSE) {
$form['fieldset'] = array(
'#type' => 'fieldset',
'#title' => 'Fieldset',
'#required' => !empty($required),
);
$form['meta'] = array(
'#type' => 'container',
......
......@@ -16,7 +16,13 @@
#}
<details{{ attributes }}>
{%- if title -%}
<summary{{ summary_attributes }}>{{ title }}</summary>
{%
set summary_classes = [
required ? 'js-form-required',
required ? 'form-required',
]
%}
<summary{{ summary_attributes.addClass(summary_classes) }}>{{ title }}</summary>
{%- endif -%}
<div class="details-wrapper">
{% if errors %}
......
......@@ -15,8 +15,14 @@
*/
#}
<details{{ attributes }}>
{%
set summary_classes = [
required ? 'js-form-required',
required ? 'form-required',
]
%}
{%- if title -%}
<summary{{ summary_attributes }}>{{ title }}</summary>
<summary{{ summary_attributes.addClass(summary_classes) }}>{{ title }}</summary>
{%- endif -%}
{% if errors %}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment