Ejemplo n.º 1
0
 /**
  * Allow extra argument to specify option for not present.
  *
  * @param array $options  options array
  * @param string $not_present_label  option to add if optional (e.g. 'Please select..')
  * @return T_Form_Select  fluent interface
  */
 function setOptions(array $options, $not_present_label = null)
 {
     if (!is_null($not_present_label)) {
         $this->no_input_key = 'not_present';
         if (array_key_exists($this->no_input_key, $options)) {
             throw new InvalidArgumentException("The key {$this->no_input_key} in options is reserved");
         }
         $options = array($this->no_input_key => $not_present_label) + $options;
         // the 'plus' operator merges these two arrays, and importantly *maintains* any numeric keys
         // while still putting the 'not present' label first. Either array_merge() and array_unshift()
         // might re-index the array if used here.
     } else {
         $this->no_input_key = null;
     }
     parent::setOptions($options);
     if (!is_null($this->no_input_key) && !$this->getDefault()) {
         $this->setDefault($this->no_input_key);
         // not present is default if other no already set
     }
     return $this;
 }
Ejemplo n.º 2
0
 /**
  * Gets a new instance of the radio element.
  *
  * @param string $alias  element alias
  * @param string $label  element label
  * @return T_Form_Radio  text input to test.
  */
 function getInputElement($alias, $label)
 {
     $input = new T_Form_Radio($alias, $label);
     $input->setOptions(array('value1' => 'Label 1', 'value2' => 'Label 2', 'value3' => 'Label 3'));
     return $input;
 }
Ejemplo n.º 3
0
 /**
  * Get the test element.
  *
  * @return T_Form_Text
  */
 function getElement($name, $label)
 {
     $element = new T_Form_Radio($name, $label);
     $element->setOptions(array('test' => '1', 'dave' => 'fred', 'swadg' => 'asdgf'));
     return $element;
 }