public function build() { $output = ""; if (parent::build() === false) { return; } switch ($this->status) { case "disabled": case "show": if (!isset($this->value)) { $output = $this->layout['null_label']; } else { $output = $this->description; } $output = "<div class='help-block'>" . $output . " </div>"; break; case "create": case "modify": foreach ($this->options as $val => $label) { $this->checked = (!is_null($this->value) and $this->value == $val); $output .= Form::radio($this->name, $val, $this->checked) . ' ' . $label . $this->separator; } $output .= $this->extra_output; break; case "hidden": $output = Form::hidden($this->name, $this->value); break; default: } $this->output = $output; }
* @param mixed $checked Value from $values to be checked as default * @param array $options Options passed to every radio button * @return string */ Form::macro('radioSwitch', function ($name, $values = null, $checked = null, $options = array()) { if (is_null($values)) { $values = [1 => transpine('helpers.yes'), 0 => transpine('helpers.no')]; $checked = is_null($checked) ? null : (int) $checked; } if (is_null($checked)) { $checked = array_keys($values)[0]; } $html = '<p class="field switch">'; foreach ($values as $value => $label) { $options['id'] = $name . $value . microtime(); $html .= Form::radio($name, $value, $checked === $value, $options); $labelClass = $value == 0 ? 'cb-disable' : 'cb-enable'; $labelClass .= $checked === $value ? ' selected' : ''; $html .= Form::label($options['id'], $label, ['class' => $labelClass]); } $html .= '</p>'; return $html; }); /** * Create a checkbox input field with forced zero value for unchecked. * * @param string $name * @param mixed $value * @param bool $checked * @param array $options * @return string