Пример #1
0
 /**
  * Builds the FormView for the control. Passwords are special
  * and the value field is never sent to the view. ie, password
  * input elements always set value="" in a form
  * @return \snb\form\FormView
  */
 public function getView()
 {
     // Do the normal thing
     $view = parent::getView();
     // then trash the value in the view, as passwords
     // should not appear in the html
     $view->set('value', '');
     return $view;
 }
Пример #2
0
 /**
  * Generates a FormView element for this field, copying all the
  * data over to the view in a view-friendly format
  * @return \snb\form\FormView
  */
 public function getView()
 {
     // Create the view
     $view = parent::getView();
     // Find out the value and force it to be true or false
     $value = $this->get('value', false) ? true : false;
     // we want to add the checked attribute if we can
     if ($value) {
         $attr = $this->get('attributes', array());
         $attr['checked'] = 'checked';
         $view->set('attributes', $attr);
     }
     // Always set the value in the checkbox control to 1
     $view->set('value', 1);
     // return it
     return $view;
 }
Пример #3
0
 /**
  * Build the view, which may consist of child elements
  * @return \snb\form\FormView
  */
 public function getView()
 {
     // Build the view
     $view = parent::getView();
     // If this set of choices is meant to be expanded,
     // then generate the child controls.
     $multiselect = $this->get('multiselect', false);
     if ($this->get('expanded', false)) {
         // yes, this is an expanded control
         $choices = $this->get('choices', array());
         // Get the value - make sure it is an array, as that simplifies the code below
         $value = $this->get('value');
         if (!is_array($value)) {
             $value = array($value);
         }
         $checkedItemCount = 0;
         $firstChild = null;
         foreach ($choices as $key => $title) {
             // make a checkbox for each item please.
             $child = new FormView();
             if ($firstChild == null) {
                 $firstChild = $child;
             }
             // We only copy over / set up a limited set of properties
             // eg. if we copied "hint", every expanded item would have
             // the same hint next to it
             $child->set('id', $this->getId() . '-' . $key);
             $child->set('label', $title);
             $child->set('value', $key);
             $child->set('name', $key);
             // Decide if we want checkboxes or radio buttons
             if ($multiselect) {
                 $child->set('type', 'checkbox');
                 $child->set('full_name', $this->getFullName() . '[' . $key . ']');
             } else {
                 $child->set('type', 'radio');
                 $child->set('full_name', $this->getFullName());
             }
             // handle attributes
             $attr = $this->get('attributes', array());
             if ($this->get('readonly')) {
                 $attr['disabled'] = 'disabled';
             }
             // See if this item is checked or not
             if (in_array($key, $value)) {
                 $attr['checked'] = 'checked';
                 $checkedItemCount++;
             }
             // Set any attributes on the control that we have been adjusting
             $child->set('attributes', $attr);
             // add it
             $view->addChild($child);
         }
         // If we created radio buttons, and none of them were checked,
         // then check the first one
         if (!$multiselect && $checkedItemCount == 0 && $firstChild != null) {
             $attr = $firstChild->get('attributes', array());
             $attr['checked'] = 'checked';
             $firstChild->set('attributes', $attr);
         }
     }
     return $view;
 }