Skip to content
Snippets Groups Projects
Unverified Commit 3f1c18a1 authored by Lauri Timmanee's avatar Lauri Timmanee
Browse files

Issue #2498791 by awset, ameymudras, balis_m, PQ, Kristen Pol, dww, morbiD,...

Issue #2498791 by awset, ameymudras, balis_m, PQ, Kristen Pol, dww, morbiD, alexpott, smustgrave: #states defaultTrigger oldValue is out of date if values are updated via a state trigger

(cherry picked from commit 47f50b9d)
parent 7bef4347
No related branches found
No related tags found
6 merge requests!8506Draft: Issue #3456536 by ibrahim tameme,!5646Issue #3350972 by nod_: [random test failure]...,!5600Issue #3350972 by nod_: [random test failure]...,!5343Issue #3305066 by quietone, Rename RedirectLeadingSlashesSubscriber,!3603#ISSUE 3346218 Add a different message on edit comment,!3555Issue #2473873: Views entity operations lack cacheability support, resulting in incorrect dropbuttons
......@@ -722,7 +722,7 @@
$document.on('state:checked', (e) => {
if (e.trigger) {
$(e.target).prop('checked', e.value);
$(e.target).prop('checked', e.value).trigger('change');
}
});
......
......@@ -31,6 +31,52 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#type' => 'textfield',
'#title' => 'Textfield trigger',
];
$form['radios_opposite1'] = [
'#type' => 'radios',
'#title' => 'Radios opposite 1',
'#options' => [
0 => 'zero',
1 => 'one',
],
'#default_value' => 0,
0 => [
'#states' => [
'checked' => [
':input[name="radios_opposite2"]' => ['value' => 1],
],
],
],
1 => [
'#states' => [
'checked' => [
':input[name="radios_opposite2"]' => ['value' => 0],
],
],
],
];
$form['radios_opposite2'] = [
'#type' => 'radios',
'#title' => 'Radios opposite 2',
'#options' => [
0 => 'zero',
1 => 'one',
],
'#default_value' => 1,
0 => [
'#states' => [
'checked' => [
':input[name="radios_opposite1"]' => ['value' => 1],
],
],
],
1 => [
'#states' => [
'checked' => [
':input[name="radios_opposite1"]' => ['value' => 0],
],
],
],
];
$form['radios_trigger'] = [
'#type' => 'radios',
'#title' => 'Radios trigger',
......
......@@ -63,6 +63,7 @@ public function testJavascriptStates() {
$this->doRadiosTriggerTests();
$this->doSelectTriggerTests();
$this->doMultipleTriggerTests();
$this->doNestedTriggerTests();
}
/**
......@@ -322,4 +323,30 @@ protected function doMultipleTriggerTests() {
$this->assertTrue($item_visible_value2_and_textfield->isVisible());
}
/**
* Tests states of radios element triggered by other radios element.
*/
protected function doNestedTriggerTests() {
$this->drupalGet('form-test/javascript-states-form');
$page = $this->getSession()->getPage();
// Find trigger and target elements.
$radios_opposite1 = $page->findField('radios_opposite1');
$this->assertNotEmpty($radios_opposite1);
$radios_opposite2 = $page->findField('radios_opposite2');
$this->assertNotEmpty($radios_opposite2);
// Verify initial state.
$this->assertEquals('0', $radios_opposite1->getValue());
$this->assertEquals('1', $radios_opposite2->getValue());
// Set $radios_opposite2 value to 0, $radios_opposite1 value should be 1.
$radios_opposite2->setValue('0');
$this->assertEquals('1', $radios_opposite1->getValue());
// Set $radios_opposite1 value to 1, $radios_opposite2 value should be 0.
$radios_opposite1->setValue('0');
$this->assertEquals('1', $radios_opposite2->getValue());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment