Example #1
0
 function render()
 {
     $id = idfy($this->name);
     if ($this->multiple) {
         JS::loadJQuery(true);
         JS::lib('jquery/plugins/localisation/jquery.localisation-min');
         JS::lib('jquery/plugins/scrollTo/jquery.scrollTo-min');
         JS::lib('jquery/ui.multiselect');
         if (!$this->nojs) {
             /*FIXME: Translation
                             JS::raw('$(function(){$.localise("ui-multiselect", {language: "en", path: "lib/js/locale/"});});');
             */
             JS::raw('$(function(){$("#' . $id . '").multiselect({' . $this->jsparams . '});});');
         }
         Head::add('ui.multiselect', 'css-lib');
         if ($this->class) {
             $this->class .= ' ';
         }
         $this->class .= 'multiselect';
     }
     $r = ($this->label === false ? '' : '<label for="' . $id . '">' . $this->label . '</label>') . '<select id="' . $id . '" name="' . $this->name . ($this->multiple ? '[]" multiple="multiple"' : '"') . ' class="' . $this->validate . ($this->validate ? ' ' : '') . $this->class . '">';
     if ($this->startEmpty) {
         $r .= '<option value="">' . ($this->startEmpty !== true ? $this->startEmpty : '') . '</option>';
     }
     if (is_array($this->data)) {
         foreach ($this->data as $value => $text) {
             if (is_array($text)) {
                 if (isset($text['id'])) {
                     $r .= $this->inflatedGroup($text);
                 } else {
                     $r .= $this->optgroup($value, $text);
                 }
             } else {
                 if (is_bool($this->selected)) {
                     $s = $this->selected;
                 } else {
                     $match_pos = array_search($value, $this->selected, true);
                     if (!$match_pos) {
                         $match_pos = array_search($value, $this->selected);
                     }
                     $match = $match_pos === false ? false : $this->selected[$match_pos];
                     $s = strcmp($match, $value) === 0;
                 }
                 $r .= '<option value="' . $value . '"' . ($s ? ' selected="selected"' : '') . '>' . $text . '</option>';
             }
         }
     }
     $r .= '</select>' . (strpos($this->validate, 'required') !== false ? '<span class="reqstar">*</span>' : '') . ($this->description ? '<span class="description">' . $this->description . '</span>' : ($this->multiple ? '&nbsp;' : ''));
     return '<span class="formelem">' . $r . '</span>';
 }