[EXTENSION] asmselectex (jQuery based)

http://www.yiiframew…on/asmselectex/

Demo: http://ironic.tnzr.n…mselectex/demo/

Screenshots: http://ironic.tnzr.n…ex/screenshots/

The orginal:

jQuery asmselect plugin: http://code.google.c…uery-asmselect/

Please post bug reports here.

This is very nice!

That's what I was going to write tomorrow. Thanks, Ironic. You have saved my time. I'll test it tomorrow.

Quote

This is very nice!

Thank you and thank you for this great framework!

Quote

Thanks, Ironic. You have saved my time. I'll test it tomorrow.

You´re welcome.

Looking forward to some feedback. ;)

updated.

http://www.yiiframew…ctex/#changelog

Hi ironic, thanks for the extension. I have some comments, questions and suggestions:

  • Is it possible to use setters and getters for the params? that way you don't need to place the checks inside the [tt]run[/tt] method. If you want to do it that way, It's simple, you just make your properties [tt]private[/tt]  and write [tt]public function setProperty[/tt] and [tt]public function getProperty[/tt] methods ;)
  • Why do you use [tt]sprintf[/tt]? is it a question of style or for anything functional? (I prefer heredoc, but that's a matter of style only, because IMHO is better for readability)
  • I also think that using [tt]CHtml[/tt] static methods is better than using HTML directly, at least more elegant (whatever that means ;D )
  • It'd be cool to make it a [tt]CInputWidget[/tt], so it could be an active or "normal" widget, using [tt]CHtml::activeDropDownList[/tt] or [tt]CHtml::dropDownList[/tt] depending on [tt]$this->hasModel[/tt]
  • Also, it would be neat to set the labels directly as widgets parameters (I know, they can be set using [tt]scriptOptions[/tt] directly anyway :) )

Oki, following the "show me da code" principle, I'm attaching my version of your extension, incorporating the changes I pointed out in my previous post :slight_smile:

Usage example:

<?php


$arrOptions = array(


                    'value1'=>'The Option text.',


                    'group1'=>array(


                                    'value2'=>'option 2',


                                    'value3'=>'option 3'


                                   ),


                    'value4'=>'option 4',


                    'value5'=>'option 5'


                   );





$this->widget('application.extensions.asmselectex.EAsmSelectEx',   


    array(


        'name' => 'asmSelect',


        'value' => $arrOptions,


        'select' => array('value1', 'value3'),


        'htmlOptions' => array('size'=>4),


        'options' => array('addItemTarget'=>'bottom','animate'=>true,'highlight'=>true,'sortable'=>true)


    )


);


?>

Hello MetaYii,

first of all, thanks for reviewing the code and your feedback.

Quote

  • Is it possible to use setters and getters for the params? that way you don't need to place the checks inside the [tt]run[/tt] method. If you want to do it that way, It's simple, you just make your properties [tt]private[/tt]  and write [tt]public function setProperty[/tt] and [tt]public function getProperty[/tt] methods ;)

All Properties, are now declared as private and have their corresponding getter and setter functions.

Note the "special" getter and setter for a single scriptOption (see end of the post).

Quote

  • Why do you use [tt]sprintf[/tt]? is it a question of style or for anything functional? (I prefer heredoc, but that's a matter of style only, because IMHO is better for readability)
  • I also think that using [tt]CHtml[/tt] static methods is better than using HTML directly, at least more elegant (whatever that means ;D )

Only 1 sprintf left. ;)

I know sprintf is a bit deprecated, but I hate <<<< operators. :D

The new renderWidget function is now completly based on CHtml static methods,

and you are right about the fact, that it looks way more elegant.

Quote

Didnt had a look at CHtml::activeDropDownList, neither at CHtml::dropDownList.

So I really dont know if they support optgroups or not.

But it would be cool to support $this->hasModel functionallity,

even if I would realy need some help on the implementation.

Quote

  • Also, it would be neat to set the labels directly as widgets parameters (I know, they can be set using [tt]scriptOptions[/tt] directly anyway :) )


$myAsmSelect->setScriptOption('removeLabel', 'revoke');


$myAsmSelect->setScriptOption('highlightAddedLabel', 'assigned: ');


$myAsmSelect->setScriptOption('highlightRemovedLabel', 'revoked: ');


$myAsmSelect->setScriptOption('sortable', true);


:)

Regarding, your second post, I totally missed your attachment :blonk:, but thanks again for your help. :)

Ahhh and 'htmlOptions' => array('size'=>4) wont really work,

because the asmselect script ignores/overwrites the html size attribute.

Here an article about "Finding a better solution for multiple selection":

http://www.ryancrame…elect_multiple/

written by the coder of the original asmselect-jquery plugin, it may

explain why there is no size-attribute anymore.

with kind regards

ironic

Updated (v 1.2)

Download: http://www.yiiframew…ectex/#download

Documentation: http://www.yiiframew…smselectex/#doc

Note: See the documentation for all changes.

Important:

  • note the camel-case for the classname! (now: EAsmSelectEx)

  • $values property is now named $data

Hi ironic,

yes, the [tt]CHtml::activeDropDownList[/tt] and [tt]CHtml::dropDownList[/tt] methods support optgroups. The advantages of using them are that you can use the form as an AR, it's shorter and, well, they'll already there.

This is the link to download the code I uploaded, BTW:

http://www.yiiframew…509.0;attach=92

(20090119: fixed some bug)

Greetz

Updated (v 1.3)

Class Changes

  • implements the suggestions of MetaYii to extend the class from CInputWidget

Script Changes

  • updated the jquery.ui.js to version 1.5.3 to keep compatibility with jQuery 1.3
  • updated the jquery.tinysort.min.js to version 1.0.2

Download: http://www.yiiframew…ectex/#download

Examples: http://www.yiiframew…smselectex/#doc

Class Documentation: http://ironic.tnzr.nl/asmselectex/

Notes on updating!

See the updated Examples and the Class Documentation for all changes.

http://www.ryancrame…s/example2.html <- is it possible with yii?

Hi,

Why it should not be possible?

You can use ironics AsmSelectEx widget and add the needed JavaScript code.

Something like:

inside your view.

Or did i get you wrong?

Greets yoshi

Thx, I’ll try it on monday in work :)

Another questions regarding this widget. Is it possible to create columns like that:

[col1][col2][col3][col4]

[value][value1][value2][remove]

[value][value1][value2][remove]

[value][value1][value2][remove]

[value][value1][value2][remove]

and to easily remove "remove button"?

What about replacing added values: when i choose another option from dropdown list, chosen value will replace the one displayed?

I'm asking this question because my javascript knowledge sucks, that why I've previously used Prado framework and now I want to switch to yii and I have this probles.

First off, excellent extension.

I had an issue and was hoping I could get some help.

Using your extension with the model, my $_POST wasn't being populated as expected. In my view:



$this->widget('application.extensions.asmselectex.EAsmSelectEx',


        array(


            'model' => $siteForm,


            'attribute' => 'problemViews',


            'data' => CHtml::listData($problemViews,'id','description'),


            'htmlOptions' => array('title'=>"Available Problem Views"),


            'scriptOptions' => array('addItemTarget'=>'bottom',


                                     'highlight'=>true,


                                     'sortable'=>false)


        )


    );


When submitting the form, my $_POST had something like:



Array


(


    [SiteForm] => Array


        (


            [username] => test


            ...


            [0] => Array(


                    [problemViews] => Array(


                            [0] => 5


                        )


                )


            [1] => Array(


                    [problemViews] => Array(


                            [0] => 11


                        )


                )


        )


instead of the desired:



Array


(


    [SiteForm] => Array


        (


            [username] => test


            ...


            [problemViews] => Array


                (


                    [0] => 5


                    [1] => 11


                )


        )


)


Looking through the generated HTML, the name for the select element was 'SiteForm[][problemViews][]'. My problem was the first '[]' which was being added on line 200 of EAsmSelectEX.php

I changed the line from:

? CHtml::activeDropDownList($this->model, $this->attribute.'[]', $this->_data, $this->htmlOptions)

to

? CHtml::activeDropDownList($this->model, $this->attribute, $this->_data, $this->htmlOptions)

which gave me what I wanted. This is the only place I'll be using the extension so I haven't looked into how that change would effect other options. Any ideas on what I was doing wrong? Or was that a necessary change?

Thanks for your work. I am using this and it looks great. I am using it as an 'active' widget and I had to make one change to get it to work. I had to drop the .'[]' in the following line.

? CHtml::activeDropDownList($this->model, $this->attribute.'[]', $this->_data, $this->htmlOptions)

It works perfect now.

Greg

My List box not selected, is there any missing in my code?




$users = t_jabatan::model()->findAll(array('select'=>array('ID_Jabatan', 'Nama_Jabatan', 'ID_Organisasi')));

	foreach($users as $user){

		$organisasi = CHtml::listData(t_organisasi::model()->findAll(array('condition'=>'ID_Organisasi=\''.$user->ID_Organisasi.'\'')), 'ID_Organisasi', 'Nama');

		$UserList[$organisasi[$user->ID_Organisasi]][$user->ID_Jabatan]=$user->Nama_Jabatan;

	}

	

	//$arrSelected = array(8, 12);


	try

	{

		$this->widget('application.extensions.asmselectex.EAsmSelectEx',

			array(

				'model' => t_jabatan::model(),

				'attribute' => "ID_Jabatan",

				'data' => $UserList,

				'selected' => array(12,2),

				'htmlOptions' => array('title'=>"Select a Item."),

				'scriptOptions' => array('addItemTarget'=>'bottom',

										 'animate'=>true,

										 'highlight'=>true,

										 'sortable'=>true),

			)

		);

	}

	catch (Exception $e) 

	{

		echo 'Caught Exception: ',  $e->getMessage(), "<br />\n";

	}



HTML Code




<select title="Select a Item." id="t_jabatan_ID_Jabatan" multiple="multiple" name="t_jabatan[ID_Jabatan][]">

<optgroup label="IT Solution">

<option value="12">Supervisor</option>

</optgroup>

<optgroup label="Computer Supply">

<option value="7">Manager</option>

<option value="8">Staff</option>

</optgroup>

<optgroup label="Open Source">

<option value="1">Sekretaris</option>

<option value="2">Administrator</option>

</optgroup>


</select>



thank for the code… this is very good one.

I have this error when add asmselectex with CJuiDatePicker together in the same form.


Error: $(input).zIndex is not a function

Source File: http://testdrive.localhost/internal/assets/20208866/js/jquery-ui.min.js

Line: 42

any one know?..

This is my CJuiDatePicker code :


			$this->widget('zii.widgets.jui.CJuiDatePicker', array(

				'name'=>'t_karyawan[Tanggal_Lahir]',

				'model'=>$model, 

				'attribute'=>'Tanggal_Lahir',

				// additional javascript options for the date picker plugin

				'options'=>array(

					'showAnim'=>'show',

					'showOn'=>'button',

					'buttonImage'=>'images/calendar.png', 

					'buttonImageOnly'=> true,

					'dateFormat'=>'dd/mm/yy',

					'yearRange'=>'1950:1995',

					'changeMonth'=>true,

					'changeYear'=>true,

				),

thx.

@gsatir


? CHtml::activeDropDownList($this->model, $this->attribute.'[]', $this->_data, $this->htmlOptions)

if you remove ‘[]’, you will only get 1 data, canot get select multiple. this just compatible yii version.

just print_r() in your model.

print_r($_POST[‘country’]); // work

print_r($this->country); // not work, no value.

ooo…

Thanks for the nice extension. It works great, but i don know how to do this:

In case of validation error in others form elements how do I keep the values selected already in EAsmSelectEx before the post action?

What happens now is that the values selected are reset in case of validation error of some form element.

Thanks in advance