Numeric Keys in Select Options Causing Duplicates in HivePress frontend listing form and throws this error when trying to save:
“test[%index%][courses]” field contains an invalid value.
Is this normal expected behavior which would require string keys only?
#Issue Description
When adding a custom select field to HivePress using hivepress/v1/models/listing/attributes
, options with numeric keys or (post IDs) appear duplicated in the generated <select>
dropdown, even though the array passed to HivePress contains only unique values.
This issue does not occur when using string-based keys, and saves without any error, suggesting HivePress may be treating numeric keys incorrectly.
#Steps to Reproduce
- Add a custom select field using the filter:
add_filter(
'hivepress/v1/models/listing/attributes',
function( $attributes ) {
$course_options = [
23 => 'Computer Science',
30 => 'Environmental Health'
];
$attributes['courses'] = [
'editable' => true,
'edit_field' => [
'label' => 'Courses',
'type' => 'select',
'_external' => true,
'_order' => 123,
'options' => $course_options,
],
];
return $attributes;
},
1000
);
- The dropdown contains duplicated options, even though
var_dump($course_options)
before returning it shows only unique values.
#Actual Result
-
The
<select>
field contains duplicated options for each numeric key. -
Example HTML output:
Computer Science Computer Science Environmental Health Environmental Health -
However, when using string keys, the issue does not occur.
Would appreciate any guidance or fixes for this! Thanks.