From 83d189e04c5c48ebc2d1a03e5b08c4b8cb75a3ff Mon Sep 17 00:00:00 2001 From: Cameron Date: Thu, 3 Dec 2020 17:31:03 -0800 Subject: [PATCH] Fix for missing dropdown selection in admin-ui edit mode. --- e107_handlers/form_handler.php | 3 ++- e107_tests/tests/unit/e_formTest.php | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/e107_handlers/form_handler.php b/e107_handlers/form_handler.php index 269f22eb9..b242d7959 100644 --- a/e107_handlers/form_handler.php +++ b/e107_handlers/form_handler.php @@ -3240,7 +3240,8 @@ var_dump($select_options);*/ } else { - $sel = is_array($selected) ? in_array($value, $selected) : ($value === $selected); + + $sel = is_array($selected) ? in_array($value, $selected) : ($value == $selected); // comparison as int/string currently required for admin-ui to function correctly. if(!empty($options['optDisabled']) && is_array($options['optDisabled'])) { diff --git a/e107_tests/tests/unit/e_formTest.php b/e107_tests/tests/unit/e_formTest.php index f4436d3bd..6f2b74a6f 100644 --- a/e107_tests/tests/unit/e_formTest.php +++ b/e107_tests/tests/unit/e_formTest.php @@ -109,7 +109,7 @@ class e_formTest extends \Codeception\Test\Unit 'bool_002' => 1, 'dropdown_001' => 'opt_value_2', - 'dropdown_002' => '1,2', + 'dropdown_002' => '2', 'textarea_001' => "the quick brown fox jumps over the lazy dog", @@ -532,6 +532,18 @@ class e_formTest extends \Codeception\Test\Unit $this->assertEquals($expected,$actual); + // Important - Test backward compatibility with selected value as string/integer combination, plus null default option. + + $selected = (string) '3'; + $opt_array = array(1=>"Option 1", 2=>"Option 2", 3=>"Option 3"); + $actual = $this->_frm->select('name', $opt_array, $selected,null,true); + + $actual = str_replace("\n", "", $actual); + $expected = ""; + + $this->assertSame($expected,$actual); + + } /* public function testUserclass() @@ -814,7 +826,7 @@ class e_formTest extends \Codeception\Test\Unit 'bool_002' => "", 'dropdown_001' => 'Label 2', - 'dropdown_002' => "", + 'dropdown_002' => "Option 2", 'textarea_001' => "the quick brown fox jumps over the lazy dog", @@ -926,7 +938,7 @@ class e_formTest extends \Codeception\Test\Unit 'dropdown_001' => "", - 'dropdown_002' => "", + 'dropdown_002' => "", 'textarea_001' => "",