@@ -25,17 +25,17 @@ class Selectize extends Nette\Forms\Controls\BaseControl
2525 private $ selectizeBack ;
2626 private $ options ;
2727 private $ prompt = FALSE ;
28-
29-
28+
29+
3030 public function __construct ($ label = null , array $ entity = NULL , array $ config = NULL )
3131 {
3232 parent ::__construct ($ label );
3333 $ this ->entity = $ entity ;
3434 $ this ->labelName = $ label ;
3535 $ this ->options = $ config ;
3636 }
37-
38-
37+
38+
3939 public function setOptions (array $ options )
4040 {
4141 foreach ($ options as $ key => $ value )
@@ -44,71 +44,71 @@ public function setOptions(array $options)
4444 }
4545 return $ this ;
4646 }
47-
48-
47+
48+
4949 public function setMode ($ mode )
5050 {
5151 $ this ->options ['mode ' ] = $ mode ;
5252 return $ this ;
5353 }
54-
55-
54+
55+
5656 public function setCreate ($ create )
5757 {
5858 $ this ->options ['create ' ] = $ create ;
5959 return $ this ;
6060 }
61-
62-
61+
62+
6363 public function maxItems ($ items )
6464 {
6565 $ this ->options ['maxItems ' ] = $ items ;
6666 return $ this ;
6767 }
68-
69-
68+
69+
7070 public function setDelimiter ($ delimiter )
7171 {
7272 $ this ->options ['delimiter ' ] = $ delimiter ;
7373 return $ this ;
7474 }
75-
76-
75+
76+
7777 public function setPlugins (array $ plugins )
7878 {
7979 $ this ->options ['plugins ' ] = $ plugins ;
8080 return $ this ;
8181 }
82-
83-
82+
83+
8484 public function setValueField ($ valueField )
8585 {
8686 $ this ->options ['valueField ' ] = $ valueField ;
8787 return $ this ;
8888 }
89-
90-
89+
90+
9191 public function setLableField ($ lableField )
9292 {
9393 $ this ->options ['lableField ' ] = $ lableField ;
9494 return $ this ;
9595 }
96-
97-
96+
97+
9898 public function setSearchField ($ searchField )
9999 {
100100 $ this ->options ['searchField ' ] = $ searchField ;
101101 return $ this ;
102102 }
103-
104-
103+
104+
105105 public function setClass ($ class )
106106 {
107107 $ this ->options ['class ' ] = $ class ;
108108 return $ this ;
109109 }
110-
111-
110+
111+
112112 /**
113113 * Sets first prompt item in select box.
114114 * @param string
@@ -129,8 +129,8 @@ public function getPrompt()
129129 {
130130 return $ this ->prompt ;
131131 }
132-
133-
132+
133+
134134 public function setValue ($ value )
135135 {
136136 if (!is_null ($ value ))
@@ -153,19 +153,19 @@ public function setValue($value)
153153 $ this ->selectizeBack = $ value ;
154154 }
155155 }
156-
156+
157157 $ this ->selectize = $ this ->selectizeBack ;
158158 }
159-
160-
159+
160+
161161 public function getValue ()
162162 {
163163 return count ($ this ->selectize )
164164 ? $ this ->selectize
165165 : NULL ;
166166 }
167-
168-
167+
168+
169169 public function loadHttpData ()
170170 {
171171 if ($ this ->options ['mode ' ] === 'select ' )
@@ -181,8 +181,8 @@ public function loadHttpData()
181181 $ this ->prepareData ();
182182 }
183183 }
184-
185-
184+
185+
186186 public function getControl ()
187187 {
188188 $ this ->setOption ('rendered ' , TRUE );
@@ -207,16 +207,16 @@ public function getControl()
207207 ->class (isset ($ this ->options ['class ' ]) ? $ this ->options ['class ' ] : 'selectize ' . ' form-control ' );
208208 }
209209 }
210-
211-
210+
211+
212212 private static function arrayUnshiftAssoc (&$ arr , $ key , $ val )
213213 {
214214 $ arr = array_reverse ($ arr , true );
215215 $ arr [$ key ] = $ val ;
216216 return array_reverse ($ arr , true );
217217 }
218-
219-
218+
219+
220220 private function prepareData ()
221221 {
222222 $ this ->selectize = $ this ->split ($ this ->getHttpData (Form::DATA_LINE ));
@@ -234,17 +234,17 @@ private function prepareData()
234234 }
235235 }
236236 }
237-
238-
237+
238+
239239 private function split ($ selectize )
240240 {
241241 $ return = \Nette \Utils \Strings::split ($ selectize , '~ ' .$ this ->options ['delimiter ' ].'\s*~ ' );
242242 return $ return [0 ] === "" ? [] : $ return ;
243243 }
244-
245-
244+
245+
246246 /**
247- *
247+ *
248248 * @author <brouwer.p@gmail.com>
249249 * @param array $array
250250 * @param type $value
@@ -253,22 +253,25 @@ private function split($selectize)
253253 */
254254 private function myInArray (array $ array , $ value , $ key )
255255 {
256- foreach ($ array as $ val )
256+ if (isset ($ array [$ key ]) AND $ array [$ key ]==$ value )
257+ {
258+ return true ;
259+ }
260+
261+ foreach ($ array as $ val )
257262 {
258263 if (is_array ($ val ))
259264 {
260265 if ($ this ->myInArray ($ val ,$ value ,$ key ))
261- return true ;
262- } else
263- {
264- if ($ array [$ key ]==$ value )
265- return true ;
266+ {
267+ return true ;
268+ }
266269 }
267270 }
268271 return false ;
269272 }
270-
271-
273+
274+
272275 public static function register ($ method = 'addSelectize ' , $ config )
273276 {
274277 Nette \Forms \Container::extensionMethod ($ method , function (Nette \Forms \Container $ container , $ name , $ label , $ entity = null , array $ options = null ) use ($ config )
0 commit comments