Skip to content
tanthammar edited this page Sep 25, 2020 · 8 revisions

Radio

Extends BaseField

Additional methods

->options(array $options = [ ])

  • Flat key => value based Array.
  • You can use a component method that returns an array; ->options($this->someMethod())

->callableOptions(callable $callable)

  • The callable should return a flat key => value array.
  • OBSERVE: that this call will be executed on EVERY re-render of the component!
  • Maybe you should consider using the options() method and set the property in mount() instead

Examples

/**
 * Radio, associative array
 */
 $options = ['Wifi' => 'wf', 'Bluetooth' => 'bl', 'Ethernet' => 'eth'];
return Radio::make('Radio')
    ->options($options)
    ->rules([Rule::in(array_values($options))])
    ->default('wf');
/**
 * Radio where labels = key
 */
$options = ['Wifi', 'Bluetooth', 'Ethernet'];
return Radio::make('Radio')
    ->options($options)
    ->rules([Rule::in($options)])
    ->default('Wifi');

Blade component

@foreach($field->options as $value => $label)
    <x-tall-radio
        :field="$field"
        :temp-key="$temp_key"
        :value="$value"
        :label="$label"
        :options-idx="$field->name.$loop->index" />
@endforeach

Styling

Extend Blade component (or override in config file)

Tanthammar\TallForms\Components\Radio::class
Clone this wiki locally