Skip to content

Commit 5e98d51

Browse files
committed
Fix dropdown value with numeric values #225
1 parent e121e33 commit 5e98d51

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

src/properties/class-papi-property-dropdown.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public function html() {
125125
if ( $settings->multiple ) {
126126
$selected = in_array( $value, $settings->selected, true );
127127
} else {
128-
$selected = papi_convert_to_string( $value ) === $settings->selected;
128+
$selected = papi_convert_to_string( $value ) === papi_convert_to_string( $settings->selected );
129129
}
130130

131131
$options_html[] = papi_html_tag( 'option', [

tests/cases/properties/class-papi-property-dropdown-test.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
*/
66
class Papi_Property_Dropdown_Test extends Papi_Property_Test_Case {
77

8-
public $slugs = ['dropdown_test', 'dropdown_test_2', 'dropdown_test_3'];
8+
public $slugs = ['dropdown_test', 'dropdown_test_2', 'dropdown_test_3', 'dropdown_test_4'];
99

1010
public function get_value() {
1111
$args = func_get_args();
1212
$args[0] = isset( $args[0] ) ? $args[0] : $this->slugs[0];
1313
switch ( $args[0] ) {
14+
case 'dropdown_test_4':
15+
return 2;
1416
case 'dropdown_test_3':
1517
return [1, 2, 3];
1618
default:
@@ -22,6 +24,8 @@ public function get_expected() {
2224
$args = func_get_args();
2325
$args[0] = isset( $args[0] ) ? $args[0] : $this->slugs[0];
2426
switch ( $args[0] ) {
27+
case 'dropdown_test_4':
28+
return 2;
2529
case 'dropdown_test_3':
2630
return [1, 2, 3];
2731
default:

tests/data/page-types/boxes/properties.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,19 @@
9191
]
9292
] ),
9393

94+
// Dropdown 4
95+
papi_property( [
96+
'type' => 'dropdown',
97+
'title' => 'Dropdown test_4',
98+
'slug' => 'dropdown_test_4',
99+
'settings' => [
100+
'items' => [
101+
'White' => 1,
102+
'Black' => 2
103+
]
104+
]
105+
] ),
106+
94107
// Editor
95108
papi_property( [
96109
'type' => 'editor',

0 commit comments

Comments
 (0)