Example #1
0
 public function render()
 {
     if ($this->callback) {
         $callback = Cogear::prepareCallback($this->callback);
         $this->setValues(call_user_func($callback));
     }
     $this->setAttributes();
     $code = array();
     foreach ($this->values as $key => $value) {
         $attributes = $this->attributes;
         $attributes['value'] = $key;
         if ($key === $this->value) {
             $attributes['checked'] = 'checked';
         }
         $code[] = HTML::tag('input', $attributes) . $value;
     }
     $code = implode("<br/>", $code);
     if ($this->wrapper) {
         $tpl = new Template($this->wrapper);
         $tpl->assign($this->attributes);
         $tpl->code = $code;
         $code = $tpl->render();
     }
     return $code;
 }
Example #2
0
 /**
  * Initialize elements
  */
 private function init()
 {
     if ($this->is_init) {
         return;
     }
     event('form.init', $this);
     event('form.init.' . $this->options->name, $this);
     if ($this->options->elements) {
         foreach ($this->options->elements as $name => $config) {
             $this->add($name, $config);
         }
         if ($this->callback && ($callback = Cogear::prepareCallback($this->callback))) {
             if ($this->result = $this->result()) {
                 call_user_func_array($callback, array($this));
             }
         }
     }
     $this->is_init = TRUE;
 }
Example #3
0
 /**
  * Initialize elements
  */
 public function init()
 {
     if ($this->initialized) {
         return;
     }
     event('form.init', $this);
     event('form.' . $this->name . '.init', $this);
     $this->is_ajaxed = isset($_REQUEST['form']) && $_REQUEST['form'] == $this->name;
     $elements = array();
     foreach ($this->elements as $name => $config) {
         $this->addElement($name, $config);
     }
     $this->initialized = TRUE;
     if ($this->callback && ($callback = Cogear::prepareCallback($this->callback))) {
         if ($result = $this->result()) {
             call_user_func_array($callback, array($result));
         } else {
             return $this->render();
         }
     }
 }