示例#1
0
 /**
  * Create the view for radio and checkbox
  * 
  * @return string
  * @throws RuntimeException
  */
 protected function createExpandedView()
 {
     $type = $this->getFormType();
     $attrs = $this->getFormAttrs($type->getAttrs());
     if ($this->isMultiple() && $type->getType() == 'radio') {
         throw new RuntimeException('The attr of the form ' . $this->getId() . '  "multiple" cannot be set with radio.');
     }
     $html = '<div class="form-group">';
     foreach ($type->getOptions() as $option) {
         $defaults = array('type' => $type->getType(), 'value' => $option['value']);
         if (is_numeric($option['value'])) {
             if ($option['value'] == $this->data) {
                 $defaults['checked'] = 'checked';
             }
         } else {
             if (is_string($option['value'])) {
                 if ($option['value'] == $this->data) {
                     $defaults['checked'] = 'checked';
                 }
             } else {
                 if ($this->isMultiple() && is_array($this->data)) {
                     if (in_array($option['value'], $this->data)) {
                         $defaults['checked'] = 'checked';
                     }
                 }
             }
         }
         $html .= '<label class="' . $type->getType() . '-inline">';
         $html .= '<input ' . \PopCode\Framework\Form\FormFactory::processAttrs(array_merge($defaults, $attrs)) . '> ' . $this->_($option['label']);
         $html .= '</label>';
     }
     $html .= '</div>';
     return $html;
 }
示例#2
0
 /**
  * {@ineritedDoc}
  */
 public function createView()
 {
     $defaults = array('type' => 'text', 'value' => (string) $this->data);
     $attrs = $this->getFormAttrs(array_merge($defaults, $this->getFormType()->getAttrs()));
     return '<input ' . FormFactory::processAttrs($attrs) . ' />';
 }
示例#3
0
 /**
  * {@ineritedDoc}
  */
 public function createView()
 {
     $attrs = $this->getFormAttrs($this->getFormType()->getAttrs());
     return '<textarea ' . FormFactory::processAttrs($attrs) . '>' . $this->data . '</textarea>';
 }