Download the PHP package reedware/nova-select-toggle-field without Composer
On this page you can find all versions of the php package reedware/nova-select-toggle-field. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package nova-select-toggle-field
Nova Select Toggle Field
This package a Laravel Nova select field whose value will vary on the contents of another select field.
Introduction
While Laravel Nova offers select drop-downs, and even the ability to search within them, sometimes I find that a different user experience is more suitable for my needs. Select boxes can sometimes be very long, and if you're unfamiliar with the resource that you're working with, you may not know where to begin with searching.
There's also some more advanced approaches that I've needed to take in the past, which involve dynamically generating the drop-down options. When the list grows in size, the computation time begins to wear down on the performance of the form.
One solution to both of these problems is something that this package attempts to offer. A "Select Toggle" is essentially a select drop-down whose options can vary based off of the contents of another drop-down.
Here's what that looks like in action:
Installation
Install this package using Composer within a Laravel Nova application:
You'll want to include the following field in any resource that you plan to use the field in:
Or you can install my Field Manager Package which aims to help reduce the plethera of field includes at the top of each resource file.
Usage
Since a Select Toggle field depends upon another field, you'll need to define at least two fields (one being the target field, and the other being the toggle field).
Abstract Example
Here's the general setup:
Concrete Example
Here's how you could recreate the introduction example within your project:
Complex Example
This section contains a complex example of something that I'm actually using in one of my projects. This is a part of my "Permission" resource, where the user can create a new permission, and tie it to a policy method. The "target" drop-down contains the list of resources in my application, and these have been grouped by their resource group. The "toggle" drop-down contains the list of permissable methods from the policy (i.e. "View Any", "Create", etc.), and it only shows the options that relate to the resource specified by the "target" drop-down.
I'm making use of two other packages here, which are optional for this example:
- My Field Manager Package, which allows me to use
Field::select(...)
instead ofSelect::make(...)
(this is to only have the oneField
include in my resources). - My Value Toggle Field, which allows me to only show certain fields based on the content of other fields. I'm using this to hide the Select Toggle field until a target option has been specified.
Here's the code: