kirschbaum-development / nova-inline-select
An inline select field for Laravel Nova apps.
Installs: 36 757
Dependents: 0
Suggesters: 0
Security: 0
Stars: 55
Watchers: 4
Forks: 15
Open Issues: 13
Requires
- php: >=7.1.0
Requires (Dev)
- codedungeon/phpunit-result-printer: ^0.26.2
- laravel/nova: *
- orchestra/testing: ^4.0
- phpunit/phpunit: ^8.3
- dev-master
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-dependabot/npm_and_yarn/ini-1.3.7
- dev-dependabot/npm_and_yarn/http-proxy-1.18.1
- dev-dependabot/npm_and_yarn/node-sass-4.14.1
- dev-dependabot/npm_and_yarn/elliptic-6.5.3
- dev-dependabot/npm_and_yarn/lodash-4.17.19
- dev-dependabot/npm_and_yarn/websocket-extensions-0.1.4
- dev-develop
This package is auto-updated.
Last update: 2021-01-11 18:52:38 UTC
README
An inline select field for Nova apps
This package contains a Nova select field that can update field values inline from the index and detail views.
Requirements
This Nova field requires Nova 1.0 or higher.
Installation
You can install this package in a Laravel app that uses Nova via composer:
composer require kirschbaum-development/nova-inline-select
Usage
Next you can use the KirschbaumDevelopment\Nova\InlineSelect
field in your Nova resource:
namespace App\Nova; use KirschbaumDevelopment\Nova\InlineSelect; class User extends Resource { // ... public function fields(Request $request) { return [ // ... InlineSelect::make('Status'), // ... ]; } }
Now you can use the InlineSelect
field just like Nova's Select
field. Now for the magic...
Inline editing
By default, the inline select field works just like a normal select field. To enable the inline editing capabilities we can use the inlineOnIndex()
and inlineOnDetail()
methods.
InlineSelect::make('Status')->options($options) ->inlineOnIndex() ->inlineOnDetail(),
Now the above inline select field will show up on both the index and detail views. When making a change to the select field, a button will display next to the field allowing you to commit the change. If you would prefer the field to auto-submit the change, just add disableTwoStepOnIndex()
or disableTwoStepOnDetail()
.
InlineSelect::make('Status')->options($options) ->inlineOnIndex() ->disableTwoStepOnIndex(),
Now changing the select field on the index view will auto-submit the changed value.
You can also add the inline select to Lenses. Use the inlineOnLens()
method. Auto-submitting works the same as well with disableTwoStepOnLens()
.
InlineSelect::make('Status')->options($options) ->inlineOnLens() ->disableTwoStepOnLens(),
Display using labels
This method works just like Nova's select field. It will display the option value rather than the option key.
InlineSelect::make('Status')->options($options) ->displayUsingLabels(),
Using closures as options()
argument
You may pass a closure to the options method. It must return a key value pair array.
InlineSelect::make('Status') ->options(function () { return [ 'one' => 'foo', 'two' => 'bar', ]; }),
Validation caveats
In the case where fields on a model are required
, which is likely, an extra step needs to be taken to ensure the inline select update persists and doesn't throw an error. The validation rule sometimes
needs to be added to the updateRules()
method on any field that is required
.
Text::make('Email') ->rules('required', 'email') ->updateRules('sometimes'),
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email brandon@kirschbaumdevelopment.com or nathan@kirschbaumdevelopment.com instead of using the issue tracker.
Credits
Sponsorship
Development of this package is sponsored by Kirschbaum Development Group, a developer driven company focused on problem solving, team building, and community. Learn more about us or join us!
License
The MIT License (MIT). Please see License File for more information.