Commit 722be736 authored by catch's avatar catch

Issue #997826 by dww, Lendude, sukanya.ramakrishnan, amar.deokar, JonMcL,...

Issue #997826 by dww, Lendude, sukanya.ramakrishnan, amar.deokar, JonMcL, larowlan, jibran, idebr: #states doesn't work correctly with type text_format
parent 54252710
......@@ -165,6 +165,11 @@ public static function processFormat(&$element, FormStateInterface $form_state,
}
}
// If the value element has #states set, copy it to the format element.
if (isset($element['value']['#states'])) {
$element['format']['#states'] = $element['value']['#states'];
}
// Prepare text format guidelines.
$element['format']['guidelines'] = [
'#type' => 'container',
......
......@@ -121,6 +121,15 @@ public function buildForm(array $form, FormStateInterface $form_state) {
],
],
];
$form['text_format_invisible_when_checkbox_trigger_checked'] = [
'#type' => 'text_format',
'#title' => 'Text format invisible when checkbox trigger checked',
'#states' => [
'invisible' => [
':input[name="checkbox_trigger"]' => ['checked' => TRUE],
],
],
];
// Checkboxes trigger.
$form['textfield_visible_when_checkboxes_trigger_value2_checked'] = [
......
......@@ -2,6 +2,7 @@
namespace Drupal\FunctionalJavascriptTests\Core\Form;
use Drupal\filter\Entity\FilterFormat;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
/**
......@@ -21,6 +22,33 @@ class JavascriptStatesTest extends WebDriverTestBase {
*/
protected static $modules = ['form_test'];
/**
* {@inheritdoc}
*/
protected function setUp():void {
parent::setUp();
// Add text formats.
$filtered_html_format = FilterFormat::create([
'format' => 'filtered_html',
'name' => 'Filtered HTML',
'weight' => 0,
'filters' => [],
]);
$filtered_html_format->save();
$full_html_format = FilterFormat::create([
'format' => 'full_html',
'name' => 'Full HTML',
'weight' => 1,
'filters' => [],
]);
$full_html_format->save();
$normal_user = $this->drupalCreateUser([
'use text format filtered_html',
'use text format full_html',
]);
$this->drupalLogin($normal_user);
}
/**
* Tests the JavaScript #states functionality of form elements.
*
......@@ -60,6 +88,10 @@ protected function doCheckboxTriggerTests() {
$this->assertNotEmpty($checkbox_unchecked_element);
$checkbox_visible_element = $page->findField('checkbox_visible_when_checkbox_trigger_checked');
$this->assertNotEmpty($checkbox_visible_element);
$text_format_invisible_value = $page->findField('text_format_invisible_when_checkbox_trigger_checked[value]');
$this->assertNotEmpty($text_format_invisible_value);
$text_format_invisible_format = $page->findField('text_format_invisible_when_checkbox_trigger_checked[format]');
$this->assertNotEmpty($text_format_invisible_format);
// Verify initial state.
$this->assertTrue($textfield_invisible_element->isVisible());
......@@ -69,6 +101,8 @@ protected function doCheckboxTriggerTests() {
$this->assertFalse($checkbox_checked_element->isChecked());
$this->assertTrue($checkbox_unchecked_element->isChecked());
$this->assertFalse($checkbox_visible_element->isVisible());
$this->assertTrue($text_format_invisible_value->isVisible());
$this->assertTrue($text_format_invisible_format->isVisible());
// Change state: check the checkbox.
$trigger->check();
......@@ -80,6 +114,8 @@ protected function doCheckboxTriggerTests() {
$this->assertTrue($checkbox_checked_element->isChecked());
$this->assertFalse($checkbox_unchecked_element->isChecked());
$this->assertTrue($checkbox_visible_element->isVisible());
$this->assertFalse($text_format_invisible_value->isVisible());
$this->assertFalse($text_format_invisible_format->isVisible());
}
/**
......
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