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) - search RESULT
  • ->searchKey(string $property) - search INPUT
  • ->default(mixed $value)
  • ->disabled()
  • ->debounce(int $milliseconds)
  • ->listWidth(string $class)

Was this helpful?

  1. Fields
  2. Fields

Search

PreviousRepeater (array)NextSelect & Multiselect

Last updated 3 years ago

Was this helpful?

Basic version, Search

Sponsor version, SearchList

1. Add the search RESULT and INPUT properties

Use unique property names if adding multiple search fields to the same component

public string|int $parent_id = 5; //SELECTED value
public array $parents = [];//search RESULT and $field->default() value
public null|string $parentSearch = ""; //search INPUT

2. Populate the properties

public function mount()
{
    $this->$parents = [ 
        5 => 'Parent five', //populate the search RESULT with existing value
    ];
    $this->parentSearch = "Parent five"; //populate the search INPUT with the existing value
}

3. Add reactivity to the search input

// update search RESULT when search INPUT is changed
public function updatedParentSearch($value)
{
    if (filled($value)) {
    //you probably want to make a query here
    //example Parents::where('name', 'like', '%' . $value . '%')->pluck('id', 'name')->take(10);
        $this->parents = [ 
            1 => 'Parent one',
            2 => 'Parent two',
            3 => 'Parent three',
        ];
    } else {
    //Clear the search options when the user clears the search input
        $this->parents = []; 
    }
}

4. Define the field

Search::make('Parent', 'parent_id')
    ->fieldWidth('w-full sm:max-w-sm')
    ->listWidth('w-full sm:w-2/3')
    ->options($this->parents) //search RESULT property
    ->searchKey('parentSearch')//search INPUT property name as string
    ->default(5) //the $key for existing value, Example: $this->model->parent_id, see mount()
    ->debounce(300) //default = 500
    ->placeholder('Search for a parent name')
    ->rules(['nullable', Rule::in(array_keys($this->parents))])

Follow the instructions on the Component tab, and add this to your blade view

<x-tall-search 
    :field="Search::blade('Search', key: 'parent_id') //key = Livewire property to STORE the value
    ->searchKey('parentSearch') //bind search INPUT to Livewire property
    ->fieldWidth('w-full sm:max-w-sm')
    ->listWidth('w-full max-w-xs')
    ->options($parents) //Livewire property holding the search RESULT
    ->default(5)
    ->debounce(500)
    ->placeholder('Search for a parent name')"
/>

Methods

->options($options) - search RESULT

  • The component property that contains the search result.

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

->searchKey(string $property) - search INPUT

  • The property that is bound to the search input

->default(mixed $value)

If you set a default value, make sure it exists in the search result property.

->disabled()

The value of $searchKey will will be displayed if the field is disabled and current field value isn't available in the initial $field->options()

This is how it is implemented in the blade file:

if($field->disabled) 
value=data_get($field->options, $field->key, data_get($this, $field->searchKey))

->debounce(int $milliseconds)

  • debounce the search input

  • default = 500

->listWidth(string $class)

  • the width of the search result dropdown

  • default = null

Please 💗 in order to get access to this field. The documentation is available in the sponsor repository.

It is required to set the initial/existing values, if you use the ->default() method on the field.

Update search RESULT when search INPUT changes, using the updatedFoo() .

sponsor this package 🔗
Read more examples on how to populate the $options on the Relations page
hook