Yii Framework Forum: [EXTENSION] asmselectex (jQuery based) - Yii Framework Forum

Jump to content

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

[EXTENSION] asmselectex (jQuery based) Rate Topic: -----

#1 User is offline   ironic 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 32
  • Joined: 09-January 09
  • Location:Germany

Posted 10 January 2009 - 02:04 AM

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

#2 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,875
  • Joined: 04-October 08
  • Location:DC, USA

Posted 10 January 2009 - 01:14 PM

This is very nice!
0

#3 User is offline   Bethrezen 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 76
  • Joined: 24-December 08
  • Location:Tambov, Russia

Posted 10 January 2009 - 01:56 PM

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

#4 User is offline   ironic 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 32
  • Joined: 09-January 09
  • Location:Germany

Posted 11 January 2009 - 04:05 AM

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. ;)


0

#5 User is offline   ironic 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 32
  • Joined: 09-January 09
  • Location:Germany

Posted 11 January 2009 - 08:18 AM

updated.

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

#6 User is offline   MetaYii 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 393
  • Joined: 07-October 08
  • Location:The Matrix

Posted 14 January 2009 - 11:44 AM

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



0

#7 User is offline   MetaYii 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 393
  • Joined: 07-October 08
  • Location:The Matrix

Posted 14 January 2009 - 10:00 PM

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

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)
    )
);
?>

Attached File(s)


0

#8 User is offline   ironic 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 32
  • Joined: 09-January 09
  • Location:Germany

Posted 16 January 2009 - 03:50 AM

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
0

#9 User is offline   ironic 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 32
  • Joined: 09-January 09
  • Location:Germany

Posted 16 January 2009 - 03:54 AM

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


0

#10 User is offline   MetaYii 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 393
  • Joined: 07-October 08
  • Location:The Matrix

Posted 16 January 2009 - 09:19 AM

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
0

#11 User is offline   ironic 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 32
  • Joined: 09-January 09
  • Location:Germany

Posted 04 February 2009 - 02:32 AM

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

#12 User is offline   morion 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 16-April 09

Posted 17 April 2009 - 05:25 AM

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

#13 User is offline   yoshi 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 170
  • Joined: 28-February 09
  • Location:Germany

Posted 17 April 2009 - 04:26 PM

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
0

#14 User is offline   morion 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 16-April 09

Posted 17 April 2009 - 09:34 PM

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

#15 User is offline   Boston 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 23-January 09

Posted 06 May 2009 - 03:47 PM

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

#16 User is offline   gsatir 

  • Junior Member
  • Pip
  • Yii
  • Group: Validating
  • Posts: 28
  • Joined: 21-April 09
  • Location:Portland, OR

Posted 31 May 2009 - 09:16 PM

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

0

#17 User is offline   fastcrash 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 245
  • Joined: 10-March 10
  • Location:South Jakarta

Posted 22 April 2010 - 02:13 AM

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

#18 User is offline   fastcrash 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 245
  • Joined: 10-March 10
  • Location:South Jakarta

Posted 22 April 2010 - 09:52 PM

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

#19 User is offline   fastcrash 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 245
  • Joined: 10-March 10
  • Location:South Jakarta

Posted 23 April 2010 - 01:39 AM

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

#20 User is offline   cadju 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 05-May 10

Posted 04 October 2010 - 07:53 PM

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