@@ -148,19 +148,12 @@ class ColorInput extends Html5Input
148
148
/**
149
149
* @inheritdoc
150
150
*/
151
- public function init ()
151
+ public function run ()
152
152
{
153
153
$ this ->type = 'color ' ;
154
154
$ this ->width = '60px ' ;
155
- parent ::init ();
156
- }
157
-
158
- /**
159
- * @inheritdoc
160
- */
161
- public function run ()
162
- {
163
155
$ this ->_msgCat = 'kvcolor ' ;
156
+ $ this ->html5Options ['value ' ] = $ this ->hasModel () ? Html::getAttributeValue ($ this ->model , $ this ->attribute ) : $ this ->value ;
164
157
$ this ->initI18N (__DIR__ );
165
158
if (substr ($ this ->language , 0 , 2 ) !== 'en ' ) {
166
159
$ this ->_defaultOptions += [
@@ -177,8 +170,9 @@ public function run()
177
170
Html::addCssClass ($ this ->options , 'spectrum-input ' );
178
171
if (!$ this ->useNative ) {
179
172
Html::addCssClass ($ this ->html5Container , 'input-group-sp ' );
180
- $ this ->pluginOptions = ArrayHelper:: merge ($ this ->_defaultOptions , $ this ->pluginOptions );
173
+ $ this ->pluginOptions = array_replace_recursive ($ this ->_defaultOptions , $ this ->pluginOptions );
181
174
}
175
+ $ this ->initInput ();
182
176
$ this ->registerColorInput ();
183
177
}
184
178
@@ -188,8 +182,6 @@ public function run()
188
182
public function registerColorInput ()
189
183
{
190
184
$ view = $ this ->getView ();
191
- $ value = $ this ->hasModel () ? Html::getAttributeValue ($ this ->model , $ this ->attribute ) : $ this ->value ;
192
- $ this ->html5Options ['value ' ] = $ value ;
193
185
ColorInputAsset::register ($ view );
194
186
if ($ this ->useNative ) {
195
187
return ;
@@ -202,6 +194,7 @@ public function registerColorInput()
202
194
}
203
195
Html5InputAsset::register ($ view );
204
196
$ input = 'jQuery("# ' . $ this ->html5Options ['id ' ] . '") ' ;
205
- $ this ->registerPlugin ('spectrum ' , $ input );
197
+ $ el = 'jQuery("# ' . $ this ->options ['id ' ] . '") ' ;
198
+ $ this ->registerPlugin ('spectrum ' , $ input , "function(){ {$ input }.spectrum('set', {$ el }.val());} " );
206
199
}
207
200
}
0 commit comments