Need help on converting from 3.4.8 to version 4.0x

15 views
Skip to first unread message

neo....@gmail.com

unread,
May 1, 2016, 11:22:26 AM5/1/16
to select2
Hi Kevin

in version prior to 4.0x i could create the complete multiselect code by php including the data selected already. You could set the option to selected and set the input values.

In short it was easy to auto load the data.

But when i load the new version of the script it does not pickup anymore the autoloaded values from the options (selected) or input (hidde) value.

How to do this by php?

Thanks for any help on this as i am banging my head on this for hours now.

Best regards,
N.


function multiselect($item) {
extract($this->option_atts(array(
"id" => "",
"default" => array(),
"value" => array(),
"size" => "5",
"chosen" => false,
"chosen_order" => false,
"class"=> "",
"page" => NULL,
"target" => NULL,
"prompt" => "",
"options" => array(),
), $item));

if(empty($value)){
$value = array();
}
if(is_string($value)){
$value = array($value);
}
if ($chosen == true){
if($class){
$class .= ' themechosen';
}else{
$class = 'themechosen';
}
}
$class = $class?' class="'.$class.'"':'';
if (!is_null($target)) {
$options += $this->get_select_target_options($target);
}
if (!is_null($page)){
$depth = $page;
$pages = get_pages();
}
if (!empty($prompt)) {
$prompt = ' data-placeholder="'.$prompt.'"';
}

if($chosen_order == true){
echo '<input type="hidden" name="_'.$id.'" value="'.implode(",",$value).'"/>';
$order = ' data-order="true"';
}else{
$order = '';
}
echo '<select'.$class.$prompt.$order.' name="' . $id . '[]" id="' . $id . '" multiple="true" size="' . $size . '" style="width:60%;height:auto" >';

foreach($options as $key => $option) {
if(is_array($option)){
echo '<optgroup label="' . $key . '">';
foreach($option as $k => $o) {
echo '<option value="' . $k . '"';
if(is_array($value) && in_array((string)$k, $value)) {
echo ' selected="selected"';
}
echo '>' . $o . '</option>';
}
echo "</optgroup>";
}else{
echo '<option value="' . $key . '"';
if(is_array($value) && in_array((string)$key, $value)) {
echo ' selected="selected"';
}
echo '>' . $option . '</option>';
}
}
echo '</select>';

}

Reply all
Reply to author
Forward
0 new messages