jmultiselect2side BUG?

This extension is great but I think I have found the following bug.

When you have multiple instances of the widget on the same page, some of the components have the same ID (if they are associated with the same model).

Specifically ModelName2side__sx and ModelName2side__dx will be the same on each instance.

The problem seems to be in the jquery.multiselect2side.js file.

var     originalName = $(this).attr("name");

if (originalName.indexOf('[') != -1)

    originalName = originalName.substring(0, originalName.indexOf('['));

var     nameDx = originalName + "ms2side__dx";

var     nameSx = originalName + "ms2side__sx";

"<div class='ms2side__select'>" +


    "<select title='" + o.labelsx + "' name='" + nameSx + "' id='" + nameSx + "' size='" + size + "' multiple='multiple' ></select>" +


"<div class='ms2side__select'>" +


    "<select title='" + o.labeldx + "' name='" + nameDx + "' id='" + nameDx + "' size='" + size + "' multiple='multiple' ></select>" +

Has anybody solved this issue?

Would it be safe to just add the attribute label to the name and id to make it unique? (at least in my scenario).

I am dynamically modifying the possible selection list with AJAX but the wrong widget is being changed.



        'type': 'POST',

        'data': $('#ModelName_id').parents("form").serialize(),

        'url': '<?php echo CController::createUrl('controller/action'); ?>',

        'cache': false,

        'dataType': 'json',

        'success': function(data){



        'error': function (xhr, ajaxOptions, thrownError){ alert(xhr.responseText); }



Could there be another way?

Thanks for your help.

OK, I believe I have fixed it.

I have replaced some code on the jquery.multiselect2side.js file.

Old Code:

originalName = originalName.substring(0, originalName.indexOf('['));

New Code:

originalName = $(this).attr("name").substring(0,$(this).attr("name").lastIndexOf('[')).replace(']', '').replace('[', '_');

I hope this helps somebody else.

I am still working on the AJAX update.

For every widget there are 3 select tags.

The first one has ID="seleccion0" and is generated automatically (I wish we could define the ID manually).

The second are third are the ones mentioned in the above message (ModelName2side__sx and ModelName2side__dx).

  • seleccion0 has all the POSSIBLE options

  • ModelName2side__dx has the AVAILABLE options

  • ModelName2side__sx has the SELECTED options

With AJAX I should be changing both seleccion0 and ModelName2side__dx . Right now I am doing just one of them. But since the ID is not controlled by me I am trying to fix this first.

Hope to help with this information.

I have also modified the Jmultiselect2side.php file.

Old Code:

$id = "seleccion".self::$idCount++;

New Code:

if ( strpos($this->name, '[') ) {

    $id = substr($this->name, 0, strrpos($this->name, '['));

    $id = str_replace(']','',$id);

    $id = str_replace('[','_',$id)."ms2side__main";

} else {

    $id = $this->name."ms2side__main";


With these changes you will have the following (in the view PHP code):



   'model'=>$model // Assume the model entity is called ModelName,










The generated HTML will have 3 corresponding SELECT tags:

<select multiple="multiple" id="ModelName_attributenamems2side__main" size="6" name="ModelName[attributename][]" style="display: none; ">

<select title="Selected" name="ModelName_attributenamems2side__sx" id="ModelName_attributenamems2side__sx" size="6" multiple="multiple">

<select title="Available" name="ModelName_attributenamems2side__dx" id="ModelName_attributenamems2side__dx" size="6" multiple="multiple">

Hope this is of some value to someone.

Best regards…

Hi guys!

I found other bug in the extension.

At file jquery.multiselect2side.js between 279 and 293 lines there are some lines with following code:

"[value=" + any_code_get_value + "]"

So jQuery throws a exception because value does not wrap with double quotes.

I changed code to

'[value="' +  any_code_get_value + '"]'

Now, javascript console there’s no error.