Default "selected" value is not set for multiple values
-
When you have a multiple value select field and select more than one value and then submit, when the form reloads the selected options are lost.
This does not happen if you only select one value.
The reason is that this plugin modfies multiple values that are posted and makes them a comma delimited string. This string is then checked to see if it matches an option to apply the “selected” attribute.
Multiple comma delimited values will not match a single value.
To fix it I change taxonomy-picker-library.php at line 335:
$selected = ''; if( empty($tpicker_inputs) ): $selected = ($data_item['value'] == ($taxonomy_name . '=' . $term->slug) ) ? 'on' : ''; else: $input_value = $tpicker_inputs[$taxonomy_name]; $selected = ( $input_value == $term->slug) ? 'on' : ''; endif;
To be this:
if( empty($tpicker_inputs) ): $selected = ($data_item['value'] == ($taxonomy_name . '=' . $term->slug) ) ? 'on' : ''; else: $input_value = $tpicker_inputs[$taxonomy_name]; // Multiple values are comma delimited. $input_value = explode(',', $input_value); if (in_array($term->slug, $input_value)) { $selected = 'on'; } endif;
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Default "selected" value is not set for multiple values’ is closed to new replies.