Simple wrapper extension for the simple and excellent miniColors jQuery color picker plugin
Requirements ¶
Yii 1.1 or above (I assume - built with Yii 1.1.8)
Usage ¶
Extract / checkout these files into the SMiniColors directory under protected/extensions
in your Yii project
This extension contains two classes:
SColorPicker Widget ¶
Generates a standard HTML input tag with the ID you specify
$this->widget('ext.SMiniColors.SColorPicker', array(
'id' => 'myInputId',
'defaultValue'=>'#000000',
'hidden'=>false, // defaults to false - can be set to hide the textarea with the hex
'options' => array(), // jQuery plugin options
'htmlOptions' => array(), // html attributes
));
SActiveColorPicker Widget ¶
Generates an "Active" HTML input for the CActiveRecord model you specify
$this->widget('ext.SMiniColors.SActiveColorPicker', array(
'model' => $model,
'attribute' => 'myModelAttribute',
'hidden'=>false, // defaults to false - can be set to hide the textarea with the hex
'options' => array(), // jQuery plugin options
'htmlOptions' => array(), // html attributes
));
nice but ...
Thanks for this nice extension thaddeusmt.
I played a little with it but could get it to attach the color picker icon to a hidden input. To support hidden fields, here is a small modification of your extension.
First, add public member to both ColorPicker classes
public $hidden=false;
Second replace the run() code with :
SColorPicker:
echo ($this->hidden == false ? CHtml::textField($this->getId(), $this->defaultValue, $this->htmlOptions) : CHtml::hiddenField($this->getId(), $this->defaultValue, $this->htmlOptions));
SActiveColorPicker:
echo ($this->hidden == false ? CHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions) : CHtml::activeHiddenField($this->model, $this->attribute, $this->htmlOptions));
This is very simple modification, and (tada) : hidden field are available !
ciao
Hidden field option added
Thanks for the tip Raoul, an easy and handy improvement! It's in the 0.2 release now. Cheers
you're welcome !
;)
Example for SActiveColorPicker
$this->widget('ext.SMiniColors.SActiveColorPicker', array( 'model' => $model, 'attribute' => 'color_attribute', 'hidden'=>false, // defaults to false - can be set to hide the textarea with the hex 'options' => array(), // jQuery plugin options 'htmlOptions' => array(), // html attributes ));
oops, thanks Clem
Had the wrong documentation for the SActiveColorPicker picker. Fixed now! Thanks
SVN
Thank you for this nice extension, it works better and is smaller than some others I've tried.
One minor annoyance : the zip file has .svn folders in it (in the "source" folder), this conflicts with my own subversion settings.
Fix the .svn issues
I removed the version control folders - I think they actually came with the jQuery plugin! Anyway the .zip is clean now. Thanks!
@thaddeusmt
Thanks for the good ext.
Super
Thanks for this nice extension
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.