[EXTENSION] EMultiSelect

Extension: http://www.yiiframework.com/extension/emultiselect/

Nice extension but with a few bugs… ;)

When add to form…




$this->widget('application.widget.emultiselect.EMultiSelect',  

  array('sortable' => true, 'searchable' => true) 

);  



Change to…




$this->widget('application.extensions.emultiselect.EMultiSelect', 		

  array('sortable' => true, 'searchable' => true)   	

); 



EmultiSelect.php - Line #60




$basePath=Yii::getPathOfAlias('application.widget.emultiselect.assets');  



Change to…




$basePath=Yii::getPathOfAlias('application.extensions.emultiselect.assets'); 



… or …




$resources = dirname(__FILE__).DIRECTORY_SEPARATOR.'assets'; 

$basePath  = Yii::app()->assetManager->publish($resources);  



Sorry, I think I developed it in the widget directory so I just updated install to have it placed in widget not extension. (That way it matches zii.widget.___ for the other for widgets.)

I have got this extension running. It looks great - thank you!

I am not sure how to go about getting the records to save. This is used to select tracks on a playlist.

My _form has the following code.

$tracks = Track::model()->findAll();

$data = array();

foreach ($tracks as $track)

$data[$track->idtrack] = $track->name . ’ '. $track->idtrack;

echo $form->dropDownList(

	$model,


	'tracks',


	$data,


	array('multiple'=>'multiple',


	 'key'=>'tracks', 'class'=>'multiselect'));

$data contains a list of all idversions, displaying the name and idversion.

Should this be saved into a char() column? Should I save the list of idtracks on the tracks column? I am getting an error when I try and do this. The error is "Array to string conversion".

Any suggestions anyone? Clearly I am fairly new to this!

Thanks

I have sorted this. Thanks anyway.

Solution found.

I recommend using foreign keys in a separate table to save things like this.

In which case, you would probably be using a manymany relation so this behavior can also help with saving: http://www.yiiframew…ons-ar-behavior

Then, Yii can autoselect things for you. (Use the key option for the dropdown.)

Eg In _form.php


<?php

    	$post=Trainingo::model()->findAll();

    	$trainings = CHtml::listData($post, 'training_id', 'name'); // Get the list of options

    	echo $form->dropDownList(

        	$model,

        	'trainingosCall',

        	$trainings,

        	array(

            	'multiple'=>'multiple',

            	'key'=>'training_id', // The id from the table

            	'class'=>'multiselect',

        	)

    	);

?>

In model relations function:


'trainingosCall' => array(

  	self::MANY_MANY,

  	'Trainingo',

  	'call_trainingo(call_id, trainingo_id)'

),

Note: I have a table call_trainingo with 2 columns call_id and trainingo_id to relate them.

Then to save (using the behavior above also):


        	$model->attributes=$_POST['Call'];

        	if (!is_array(@$_POST['Call']['trainingosCall'])) {

            	$_POST['Call']['trainingosCall2'] = array();

        	}

        	$model->setRelationRecords(

            	'trainingosCall', $_POST['Call']['trainingosCall']

        	);

        	$model->save();

Thanks for making this extension - using it in one of my projects and its AWESOME.

One enhancement I was thinking about is a shortcut to creating additional items in the ‘other’ table of relations.

For example, lets use a MANY_MANY relationship of Posts and Categories.

When using eMultiSelect I can display a post with related categories and assign them dynamically on the fly. It would be nice to be able to add additional categories on the fly while doing the assignment in the post model.

I also have a ‘categories’ management in my app but trying to think of a good way to do this… part of this extension or just a secondary form on the same page?

Thanks.

Let me make sure I understand first, you are basically wanting a way to add additional options (in your case categories) via AJAX (which would create the new option in the database and update the list)?

I think you would probably have to build that in yourself, though you might find an extension to make it work. You would need to have an AJAX handler in the controller and a field that could post the new category, then it would need to add the option to your dropdown and possibly refresh the multiselect thing to get it to update.

Alternatively, it might be easier to just use JS on the client side and then deal with the added options on save rather than adding them via AJAX. Then of course you would be validating later on the new options so you might run into some validation issues on the new category that you would have to handle.

I hope that make some since and helps a little. I will be happy to guide you as much as possible as you go, but I don’t think I will be able to code it.

(As a side note, minus the refreshing of the jquery multiselect, this would be exactly the same as if you weren’t using EMultiSelect because all I’ve done is change a JQuery addon to where it plays nicely with Yii Extensions.)

Thanks for the extension!

It worked for me with MANY_MANY mode, when

  • Set the foreign keys in the intermediate table. That was possible when

– All related tables’ ENGINE=InnoDB

– There are only valid values in that table (or empty table)

Although obvious for most people, maybe it helps newcomers (like me) :)

hello…

I want to update existing data with ajax.

data is changed, but not refreshed …

I think want to put a trigger to click the remove-all so the results can be refreshed

is it possible?<br>and it is possible to add onchange???<br>

I’m not sure I completely understand, but I’m sure it is possible if you read the manual for the underlying jQuery extension http://www.quasipart…at/multiselect/

You may have to modify my code somewhat to allow you to set

Their also appear to be a next version that supports AJAX

[b]

My addon essentially just wraps the jQuery plugin so feel free to see how that is done to wrap one of the other verisons or to use features out of this version.

hello … sorry to bother … I use your extension and datepicker in a form … but extension datepicker does not work properly datepicker enxtension ::http://www.yiiframework.com/extension/jui/ Because of what Things like this happen?

and 1 more

when I click the plus sign in a hurry, the value in Colom selected become duplicate

2000

emulti.JPG

I run it in mozilla6.0

duplicate

2001

emulti_doble.JPG

Yii has datepicker built in now so you should not need to use that extension.

http://www.yiiframework.com/doc/api/1.1/CJuiDatePicker

As far as the doubling goes. I cannot reproduce it on my system, but that is an error in the js of the extension so you can report that to the js extension creator here: http://www.quasipartikel.at/multiselect/

If he makes changes, please update me so I can correct the copy of his js in my code.

hi loren…

I think jquery multiselect been updated

https://github.com/crdeutsch/multiselect ;D ;D ;D

ok, I just updated the extension.

Thank you so much for the great example you made here in this thread,

now I have a height issue, the multiselect does not want to obey me :P I changed to:


/* multiselect styles */

	.multiselect {

		width: 660px;

		height: 400px;

	}

The width changes, but not the height. I’ve tried cleaning the root assets folder(where yii publishes everything).

Didn’t work (was not required for the width to change anyway…)

So I inspected it with firebug and I’ve found the problem,




<ul class="selected connected-list ui-sortable" style="height:32px">

<ul class="available connected-list" style="height: 32px;">

Cant find though where these attributes come from, any idea?

Open up the javascript file in the extensions folder.

I’ve ofcoursed checked thrue that and the .css file already…

This looks great, I will have to give it a try. Hopefully everyone else here has solved the bugs for me :)

Hi, I have a question. I have three tables: User(userID, etc), Owner(ownerID, etc) and UserToOwner(userID, ownerID). Relation between User and Owner is MANY_MANY.

I am displaying all Owners in the table so the user can populate userToOwner, but I’d also like to display all owners that are related to user(userToOwner) as selected. Is it possible?

Got it sorted, nevermind.

If you ever get this problem, just create an array of values to be selected, ie:

foreach($model->owners as $ownerID)

{

&#036;array[&#036;ownerID-&gt;ownerID] = array(&quot;selected&quot;=&gt;true);

}

and pass $array to options: ‘options’=>$array