TALL-forms
  • TALL-forms
  • Installation
    • Quickstart: Artisan cmd
    • Manual installation
      • Package
      • Translations
      • Css & Theme
      • Javascript
      • Tailwind
      • Laravel Mix
      • Wrapper view
      • Laravel Jetstream/Breeze
  • Upgrade v7 to v8
    • Configuration changes
    • Component & Field changes
    • Blade view changes
    • Notification changes
    • Styling changes
  • Concept
    • Configuration
    • Validation
    • Styling
    • Icons
    • Javascript
    • Layout vs Wrapper
    • Model binding
    • Manually saving data
    • Extend Blade Components
  • Create Forms
    • Form Data
    • Form Types
      • Standard form
      • As modal
      • Without buttons
      • Fields only
      • Headless
    • Form attributes
    • Form buttons
    • Form slots
    • Form methods
    • Lifecycle hooks
    • Render a form
    • Mass generate
  • Fields
    • Declaration
    • Labels
    • Field Slots
    • Field methods
    • Custom field attributes
    • Conditional field
    • Custom view
    • Custom field
    • Custom Livewire component
    • Relations
    • Fields
      • Checkbox
      • Checkboxes
      • FileUpload
      • Honeypot
      • ImageCropper
      • Input
      • Password
      • InputArray
      • KeyVal (array)
      • Radio
      • Range
      • Repeater (array)
      • Search
      • Select & Multiselect
      • Tags
      • TagsSearch
      • Textarea
      • Trix
      • SpatieTags
    • Sponsor Fields
      • More Inputs
      • CKEditor
      • DatePicker
      • Heading
      • Markdown
      • Panels
      • SearchList
      • SelectOptGroup
      • Tabs
      • Trix, file-uploads
  • Blade components
    • Notifications
    • Label wrapper
    • Button
    • Modal blade component
    • Modal form blade component
  • Examples
    • Input examples
    • Array fields example
Powered by GitBook
On this page
  • Methods
  • ->options($options)
  • ->placeholder(string $placeholder)

Was this helpful?

  1. Fields
  2. Fields

Select & Multiselect

PreviousSearchNextTags

Last updated 3 years ago

Was this helpful?

The options can be callable or associative/flat array

$options = ['Wifi' => 'wf', 'Bluetooth' => 'bl', 'Ethernet' => 'eth'];
$options = ['Wifi', 'Bluetooth', 'Ethernet'];

Select

Does not use @entangle.

Select::make('Select')
    ->options($options)
    ->default('wf')
    ->fieldWidth('w-full sm:max-w-sm')
    ->wire('defer')// if you don't want a network request on every selection
    ->rules(['nullable', Rule::in(array_values($options))]);

Multiselect

Uses @entangle. Is deferred by default.

MultiSelect::make('Multi Select')
    ->options($options)
    ->default(['wf'])
    ->deferEntangle(false)//remove if you want the field to be deferred
    ->fieldWidth('w-full sm:max-w-sm')
    ->wire('defer')// if you don't want a network request on every selection
    ->rules(['nullable', Rule::in(collect($options)->values()->implode(','))]);

value is a string

Livewire example

public null|string $select = 'bl';
public array $options = ['wf' => 'Wifi', 'bl' => 'Bluetooth', 'eth' => 'Ethernet'];
<x-tall-select 
    :field="Select::blade('select')
    ->options($options)
    ->default('wf')
    ->fieldWidth('w-full sm:max-w-sm')"
/>

value is an array

Livewire example

public array $multiselect = ['bl'];
public array $options = ['wf' => 'Wifi', 'bl' => 'Bluetooth', 'eth' => 'Ethernet'];
<x-tall-multiselect 
    :field="MultiSelect::blade('multiselect')
    ->options(['Wifi' => 'wf', 'Bluetooth' => 'bl', 'Ethernet' => 'eth'])
    ->custom() //save the data with saveFoo() event hook
    ->default(['wf'])
    ->fieldWidth('w-full sm:max-w-sm')"
/>
//tall-theme.css
.form-select
.form-multiselect

//or extend the blade class

Methods

->options($options)

  • A list or flat key => value based Array, Collection or Closure.

  • OBSERVE: if you use a callable, it will be executed on EVERY re-render of the component! Maybe you should consider setting the $options in mount() instead?

  • Tip: use a component method that returns an array; ->options($this->someMethod())

->placeholder(string $placeholder)

Display a message when no item is selected.