SearchableSelectHelper
in package
Helper class for rendering searchable select components.
Provides methods for building Alpine.js searchable select dropdowns that can filter options as the user types.
Tags
Table of Contents
Methods
- forLanguages() : string
- Render a searchable select component for languages.
- render() : string
- Render a generic searchable select component.
- buildConfig() : string
- Build the Alpine.js x-data config JSON.
Methods
forLanguages()
Render a searchable select component for languages.
public
static forLanguages(array<int, array{id: int|string, name: string}> $languages, int|string|null $selected, array{name: string, id: string, placeholder?: string, required?: bool, dataAction?: string, dataAjax?: bool, dataRedirect?: string, size?: string, class?: string} $options) : string
Parameters
- $languages : array<int, array{id: int|string, name: string}>
-
Language options
- $selected : int|string|null
-
Selected language ID
- $options : array{name: string, id: string, placeholder?: string, required?: bool, dataAction?: string, dataAjax?: bool, dataRedirect?: string, size?: string, class?: string}
-
Configuration options
Return values
string —HTML for the searchable select component
render()
Render a generic searchable select component.
public
static render(array<int, array{value: string, label: string}> $items, string $selected, array{name: string, id: string, placeholder?: string, required?: bool, dataAction?: string, dataAjax?: bool, dataRedirect?: string, size?: string, class?: string} $options) : string
Parameters
- $items : array<int, array{value: string, label: string}>
-
Option items
- $selected : string
-
Selected value
- $options : array{name: string, id: string, placeholder?: string, required?: bool, dataAction?: string, dataAjax?: bool, dataRedirect?: string, size?: string, class?: string}
-
Configuration options
Return values
string —HTML for the searchable select component
buildConfig()
Build the Alpine.js x-data config JSON.
private
static buildConfig(array<int, array{value: string, label: string}> $items, string $selected, array{name: string, id: string, placeholder?: string, required?: bool, dataAction?: string, dataAjax?: bool, dataRedirect?: string, size?: string, class?: string} $options) : string
Parameters
- $items : array<int, array{value: string, label: string}>
-
Option items
- $selected : string
-
Selected value
- $options : array{name: string, id: string, placeholder?: string, required?: bool, dataAction?: string, dataAjax?: bool, dataRedirect?: string, size?: string, class?: string}
-
Configuration options
Return values
string —JSON config string