Yii Framework Forum: jmultiselect2side BUG? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

jmultiselect2side BUG? Multiple instances of this widget have the same ID Rate Topic: -----

#1 User is offline   CocoJames 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 05-June 12

Posted 05 June 2012 - 12:26 PM

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.


$(document).ready(function(){
    $.ajax({
        'type': 'POST',
        'data': $('#ModelName_id').parents("form").serialize(),
        'url': '<?php echo CController::createUrl('controller/action'); ?>',
        'cache': false,
        'dataType': 'json',
        'success': function(data){
                    $('#ModelName2side__dx').html(data);
                },
        'error': function (xhr, ajaxOptions, thrownError){ alert(xhr.responseText); }
    })
})


Could there be another way?

Thanks for your help.
0

#2 User is offline   CocoJames 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 05-June 12

Posted 05 June 2012 - 02:33 PM

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.
0

#3 User is offline   CocoJames 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 05-June 12

Posted 05 June 2012 - 03:31 PM

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):

<?php
   $this->widget('application.extensions.jmultiselect2side.Jmultiselect2side',array(
   'model'=>$model // Assume the model entity is called ModelName,
   'attribute'=>'attributename',
   'labelsx'=>'Selected',
   'labeldx'=>'Available',
   'autoSort'=>'true',
   'selectedPosition'=>'left',
   'moveOptions'=>false,
   'list'=>array(),
));
?>


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...
0

#4 User is offline   C├ęsar Albuquerque 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 29-March 12

Posted 12 March 2014 - 10:14 AM

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.
Thanks.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users