techouse / select-auto-complete
该软件包已被放弃,不再维护。未建议替代软件包。
自动完成 Laravel Nova 搜索字段。
v1.4.1
2022-02-13 20:34 UTC
Requires
- php: >=7.1.0
- illuminate/support: ^5.6 || ^6.0 || ^7.0 || ^8.0 || ^9.0
- laravel/nova: *
README
自动完成 Laravel Nova 搜索字段。
提供在选择输入字段内自动完成搜索结果的能力。
安装
您可以通过 composer 将该软件包安装到使用 Nova 的 Laravel 应用中
composer require techouse/select-auto-complete
使用
API 通过添加以下附加选项扩展了 Nova 的默认 Select
字段
- default - 可选 - 在字段为空时设置默认值。默认为
null
。 - maxResults - 可选 - 每次显示的结果数量。必须是正 整数。默认为
30
。 - maxHeight - 可选 - 选择下拉列表的高度。默认为
220px
。 - displayUsingLabels - 可选 - 仅显示选项列表的标签。默认为禁用,显示键和标签。
- placeholder - 可选 - 使用自定义占位符。
简单地使用 SelectAutoComplete
类代替直接使用 Select
或像以下示例那样别名,这样您就不必重构太多现有代码。
<?php namespace App\Nova\Actions; use App\AccountData; use Illuminate\Bus\Queueable; use Laravel\Nova\Actions\Action; use Illuminate\Support\Collection; use Laravel\Nova\Fields\ActionFields; use Illuminate\Queue\SerializesModels; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Contracts\Queue\ShouldQueue; use Techouse\SelectAutoComplete\SelectAutoComplete as Select; class EmailAccountProfile extends Action { use InteractsWithQueue, Queueable, SerializesModels; /** * Perform the action on the given models. * * @param \Laravel\Nova\Fields\ActionFields $fields * @param \Illuminate\Support\Collection $models * @return mixed */ public function handle(ActionFields $fields, Collection $models) { foreach ($models as $model) { (new AccountData($model))->send(); } } /** * Get the fields available on the action. * * @return array */ public function fields() { return [ Select::make(__('Person'), 'person') ->options(\App\Person::all()->mapWithKeys(function ($person) { return [$person->id => $person->name]; })) ->displayUsingLabels(), Select::make(__('Partner'), 'partner') ->options(\App\User::all()->pluck('name', 'id')) ->placeholder('Pick a name') // use a custom placeholder ->displayUsingLabels() // display only the labels od the options list ->default(7) // set the default to the User with the ID 7 ->maxResults(5) // limit the dropdown select to a max of 5 hits ->maxHeight('100px') // limit the dropdown to a max height of 100px ->required() // make the field required ]; } }