镭 /
filament-flags-dropdown
用于Filament表单的标志下拉字段
v0.2.0
2023-07-12 13:35 UTC
Requires
- php: ^8.1
- filament/filament: ^2.0
- illuminate/contracts: ^10.0
- spatie/laravel-package-tools: ^1.14.0
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.9
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^8.0
- pestphp/pest: ^2.0
- pestphp/pest-plugin-arch: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
This package is auto-updated.
Last update: 2024-09-10 01:34:11 UTC
README
带有标志和自定义标签的下拉字段。该字段可用作Filament表单中的国家或语言选择器(Filament forms)。
此包利用flag-icons来显示国家标志。
安装
您可以通过Composer安装此包
composer require ranium/filament-flags-dropdown
您可以使用(可选)发布配置文件
php artisan vendor:publish --tag="filament-flags-dropdown-config"
使用方法
现在您可以在表单生成器中使用FlagsDropdown字段。您需要提供要显示在下拉菜单中的选项。
选项数组键应该是国家的ISO 3166-1-alpha-2代码,而值应该是选项的数组,包含value
和label
。在以下示例中,当从下拉菜单中选择“India”时,将在数据库中保存IND
。
use Ranium\FlagsDropdown\Forms\Components\Fields\FlagsDropdown; public static function form(Form $form): Form { $countries = [ 'in' => ['value' => 'IND', 'label' => 'India'], 'us' => ['value' => 'USA', 'label' => 'United States'], ]; return $form ->schema([ // ... Other fields FlagsDropdown::make('country') ->options($countries), // Chain your field modifiers here // Other fields ]); }
如果希望下拉菜单的value
与label
相同,则选项可以构建如下
$countries = [ 'in' => 'India', 'us' => 'United States' ];
在这种情况下,当选择该选项时,字段的值将是“India”。
事件
字段在值更改时触发事件。您可以监听事件并将其绑定到可调用函数。新值和旧值作为参数传递给可调用函数。
use Filament\Pages\Page; use Filament\Forms\Concerns\InteractsWithForms; use Ranium\FlagsDropdown\Forms\Components\Fields\FlagsDropdown; class Settings extends Page { use InteractsWithForms; protected static ?string $navigationIcon = 'heroicon-o-document-text'; protected static string $view = 'filament.pages.settings'; protected function getFormSchema(): array { return [ FlagsDropdown::make('language') ->options(['in' => 'Hindi', 'gb' => 'English']) ->onChange($this->doSomething(...)), ]; } public function doSomething(?string $newValue, ?string $oldValue) { // This method will be called whenever the value of the // dropdown changes in the frontend } }
测试
composer test
变更日志
请参阅CHANGELOG以获取有关最近更改的更多信息。
贡献
请参阅CONTRIBUTING以获取详细信息。
安全漏洞
请审查我们的安全策略,了解如何报告安全漏洞。
鸣谢
许可证
MIT许可证(MIT)。请参阅许可证文件以获取更多信息。