radio() public method

public radio ( $name, $options = [] )
Esempio n. 1
0
 public function testRadio()
 {
     //test where valueOrArray is array
     $html = $this->object->radio('element', 'value', array('arbitrary' => 'arbitrary', 'class' => 'test-class'));
     $this->assertAttributes($html, array('class' => array('test-class', 'ccm-input-radio'), 'arbitrary' => 'arbitrary'));
     //test where valueOrArray is value
     $html = $this->object->radio('element', 'value', 'value', array('arbitrary' => 'arbitrary', 'class' => 'test-class'));
     $this->assertAttributes($html, array('class' => array('test-class', 'ccm-input-radio'), 'arbitrary' => 'arbitrary', 'checked' => 'checked'));
 }
 public function radio($fieldName, $radioOptions, $options)
 {
     $options['legend'] = false;
     $options['separator'] = "\n";
     $out = parent::radio($fieldName, $radioOptions, $options);
     $out = $this->_restructureLabel($out, array('class' => 'radio'));
     return $out;
 }
Esempio n. 3
0
 /**
  * Outputs a list of radio form elements with the proper
  * markup for twitter bootstrap styles
  *
  * @param array $options
  * @param array $attributes
  * @access public
  * @return string
  */
 public function radio($field, $options = array(), $attributes = array())
 {
     if (is_array($field)) {
         $options = $field;
     } else {
         $options["field"] = $field;
     }
     if (!isset($options["options"]) || !isset($options["field"])) {
         return "";
     }
     $opt = $options["options"];
     unset($options["options"]);
     $inputs = "";
     $hiddenField = isset($options['hiddenField']) && $options['hiddenField'];
     foreach ($opt as $key => $val) {
         $input = parent::radio($options["field"], array($key => $val), $attributes + array("label" => false, 'hiddenField' => $hiddenField));
         $id = array();
         preg_match_all("/id=\"[a-zA-Z0-9_-]*\"/", $input, $id);
         if (!empty($id[0])) {
             $id = end($id[0]);
             $id = substr($id, 4);
             $id = substr($id, 0, -1);
             $input = $this->Html->tag("label", $input, array("class" => "radio", "for" => $id));
         }
         $inputs .= $input;
     }
     $options["input"] = $inputs;
     return $this->input($options);
 }
Esempio n. 4
0
 /**
  * radio method override for purchasable option
  *
  * ex.
  * echo $this->Form->input('Category.Category', array(
  *    'type' => 'radio',
  *    'purchasable' => true, // must be set to true
  *    'combine' => array('{n}.Category.id', '{n}.Category.name'), // what the
  * list should look like
  *    'options' => $categories  // a full data array from find "all", not a
  * normal find "list" type
  *    ));
  *
  */
 public function radio($fieldName, $options = array(), $attributes = array())
 {
     if ($attributes['purchasable'] === true && !empty($attributes['combine'])) {
         $combine = explode('.', $attributes['combine'][0]);
         $key = $combine[2];
         $combine = explode('.', $attributes['combine'][1]);
         $model = $combine[1];
         $value = $combine[2];
         unset($attributes['purchasable']);
         unset($attributes['combine']);
         $out = '';
         for ($i = 0; $i < count($options); $i++) {
             $id = $options[$i][$model][$key];
             $label = $options[$i][$model][$value];
             if ($i > 0) {
                 $attributes['hiddenField'] = false;
                 // because we're doing individual radio buttons we need to remove all but the
                 // first hidden field as it would be normally
             }
             if (!empty($options[$i]['Product']) && empty($options[$i]['TransactionItem'])) {
                 // must be purchased, and hasn't been yet (in the
                 // Products/Model/Behavior/PurchasableBehavior)
                 $out .= parent::radio($fieldName, array($id => __('<span style="text-decoration: line-through">%s</span> <a href="/products/products/view/%s" class="btn btn-mini btn-success">Buy</a>', $label, $options[$i]['Product']['id'])), $attributes + array('disabled' => 'disabled'));
             } else {
                 $out .= parent::radio($fieldName, array($id => $label), $attributes);
             }
         }
         //$options = Set::combine($options, $attributes['combine'][0],
         // $attributes['combine'][1]);
         return $out;
     } else {
         return parent::radio($fieldName, $options, $attributes);
     }
 }
Esempio n. 5
0
 public function testRadio()
 {
     $this->assertEqual(FormHelper::radio('name', 'value', null, array('class' => 'myClass')), '<input type="radio" name="name" class="myClass" value="value">');
     $this->assertEqual(FormHelper::radio('name', 'value', 'value', array('class' => 'myClass')), '<input type="radio" name="name" class="myClass" value="value" checked="checked">');
     $this->assertEqual(FormHelper::radio('name', $this->Model, 'obj', array('class' => 'myClass')), '<input type="radio" name="name" class="myClass" value="obj" checked="checked">');
 }
Esempio n. 6
0
 /**
  * Creates a set of radio widgets.
  *
  * ### Attributes:
  *
  * - `label` - Create a label element for the radio buttons in the left column
  * - `value` - indicate a value that is should be checked
  * - `disabled` - Set to `true` or `disabled` to disable all the radio buttons.
  * - `help` - Add a message under the radio buttons to give more informations
  * - `inline` - Align all the radio buttons
  *
  * @param string $fieldName Name of a field, like this "Modelname.fieldname"
  * @param array $options Radio button options array (as 'value'=>'Text' pairs or as array('label' => 'text', 'help' => 'informations')
  * @param array $attributes Array of HTML attributes, and special attributes above.
  * @return string Completed radio widget set.
  */
 public function radio($fieldName, $options = array(), $attributes = array())
 {
     $out = '';
     $inline = isset($attributes['inline']) && true === $attributes['inline'] ? true : false;
     unset($attributes['inline']);
     $defaultAttributes = array('legend' => false, 'label' => false);
     $defaultAttributes['separator'] = $inline ? '</label><label class="radio-inline">' : '</label></div><div class="radio"><label>';
     $attributes = $this->__errorBootstrap($fieldName, $attributes);
     $attributes = Hash::merge($defaultAttributes, $attributes);
     $attributesForBefore = $attributes;
     unset($attributes['state']);
     unset($attributes['help']);
     $attributes['label'] = false;
     $radio = parent::radio($fieldName, $options, $attributes);
     return $this->__buildRadioBefore($fieldName, $attributesForBefore, $inline) . $radio . $this->__buildRadioAfter($inline, $attributesForBefore);
 }
Esempio n. 7
0
 /**
  * FormExtHelper::radio()
  * Overwrite to avoid "form-control" to be added.
  *
  * @param mixed $fieldName
  * @param mixed $options
  * @param mixed $attributes
  * @return void
  */
 public function radio($fieldName, $options = array(), $attributes = array())
 {
     $attributes = $this->_initInputField($fieldName, $attributes);
     if (!empty($attributes['class']) && $attributes['class'] == array('form-control')) {
         $attributes['class'] = false;
     }
     return parent::radio($fieldName, $options, $attributes);
 }