All Projects → yassilah → laravel-nova-nested-form

yassilah / laravel-nova-nested-form

Licence: other
This package allows you to include your nested relationships' forms into a parent form.

Programming Languages

PHP
23972 projects - #3 most used programming language
Vue
7211 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to laravel-nova-nested-form

Laravel Nova Nested Form
This package allows you to include your nested relationships' forms into a parent form.
Stars: ✭ 169 (-24.89%)
Mutual labels:  form, nova
vue-form-2
Vue.js 2 Form Component
Stars: ✭ 60 (-73.33%)
Mutual labels:  form
nova-tabs
Another Laravel Nova Tabs Package
Stars: ✭ 60 (-73.33%)
Mutual labels:  nova
TextFieldsTraversalController
A controller to manage the traversal of a collection of textfields.
Stars: ✭ 15 (-93.33%)
Mutual labels:  form
vue-elementui-freedomen
elementui 应用级框架
Stars: ✭ 27 (-88%)
Mutual labels:  form
stook
A minimalist design state management library for React.
Stars: ✭ 86 (-61.78%)
Mutual labels:  form
react-cool-form
😎 📋 React hooks for forms state and validation, less code more performant.
Stars: ✭ 246 (+9.33%)
Mutual labels:  form
BulkPDF
BulkPDF is a free and easy to use open source software, which allows to automatically fill an existing PDF form with differen values. Only a spreadsheet (Microsoft Excel 2007/2010/2013, LibreOffice or OpenOffice Calc) with the desired values is required.
Stars: ✭ 94 (-58.22%)
Mutual labels:  form
grapesjs-plugin-forms
Set of form components and blocks for the GrapesJS editor
Stars: ✭ 39 (-82.67%)
Mutual labels:  form
nova-mailman
Conveniently route all emails to a local mailbox.
Stars: ✭ 47 (-79.11%)
Mutual labels:  nova
GenerateDynamicCustomForm
You can generate a dynamic form view in a few minutes for a signup, add a record. Creating a form is very easy.
Stars: ✭ 18 (-92%)
Mutual labels:  form
lc-spring-data-r2dbc
An extension of spring-data-r2dbc to provide features such as relationships, joins, cascading save/delete, lazy loading, sequence, schema generation, composite id
Stars: ✭ 30 (-86.67%)
Mutual labels:  relationships
bulma-material-form
Material Design Form Elements for Bulma (CSS Only)
Stars: ✭ 26 (-88.44%)
Mutual labels:  form
autoform
🤖📝 AutoForm is the simplest way to automatically generate fast, beautiful and standards/WCAG compliant HTML forms based on an Ecto Schema in a Phoenix Web Application to *significantly* speed up Web App Development. 🚀
Stars: ✭ 18 (-92%)
Mutual labels:  form
laravel-nova-order-nestedset-field
Laravel Nova field that make your resources orderable
Stars: ✭ 21 (-90.67%)
Mutual labels:  nova
designable
🧩 Make everything designable 🧩
Stars: ✭ 2,156 (+858.22%)
Mutual labels:  form
json-schema-js-gui-model
Handy gui model and associated translator that can be used to construct javascript UI forms from json-schemas
Stars: ✭ 19 (-91.56%)
Mutual labels:  form
dynamic-input-fields-reactjs
Example of the dynamic input fields in ReactJS
Stars: ✭ 31 (-86.22%)
Mutual labels:  form
eloquent-has-by-join
Convert has() and whereHas() constraints to join() ones for single-result relations.
Stars: ✭ 21 (-90.67%)
Mutual labels:  relationships
jquery.niceform
The jQuery plugin for validation and post form data to server
Stars: ✭ 16 (-92.89%)
Mutual labels:  form

Latest Stable Version Total Downloads Latest Unstable Version License Monthly Downloads Daily Downloads

Nova Nested Form

This package allows you to include your nested relationships' forms into a parent form.

Installation

composer require yassi/nova-nested-form

Contributions

As I did not anticipate so many people would use that package (which is awesome) and simply do not have enough time to update/enhance this package more regularly on my own, I am looking for other contributors to help me with the maintenance and feature requests. Don't hesitate to contact me if you're interested!

Update to 3.0

The afterFill and beforeFill methods are no longer available.

Attach a new relationship form to a resource

Simply add a NestedForm into your fields. The first parameter must be an existing NovaResource class and the second parameter (optional) must be an existing HasOneOrMany relationship in your model.

namespace App\Nova;

use Laravel\Nova\Fields\ID;
use Illuminate\Http\Request;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Fields\Gravatar;
use Laravel\Nova\Fields\Password;
// Add use statement here.
use Yassi\NestedForm\NestedForm;

class User extends Resource
{
    ...
    public function fields(Request $request)
    {
        return [
            ID::make()->sortable(),

            Gravatar::make(),

            Text::make('Name')
                ->sortable()
                ->rules('required', 'max:255'),

            Text::make('Email')
                ->sortable()
                ->rules('required', 'email', 'max:254')
                ->creationRules('unique:users,email')
                ->updateRules('unique:users,email,{{resourceId}}'),

            Password::make('Password')
                ->onlyOnForms()
                ->creationRules('required', 'string', 'min:6')
                ->updateRules('nullable', 'string', 'min:6'),

            // Add NestedForm here.
            NestedForm::make('Posts'),
        ];
    }

Choose when to display the form

For instance, if the nested form should only be available if the value of the "has_comments" attirbute is true, you can use:

class Post extends Resource
{
    ...
    public function fields(Request $request)
    {
        return [
            Boolean::make('Has Comments'),
            NestedForm::make('Comments')->displayIf(function ($nestedForm, $request) {
               return [
                    [ 'attribute' => 'has_comments', 'is' => true ]
               ];
        ];
    }
})

The displayIf method is excepted to return an array of array as you may want to add several conditions.

class Post extends Resource
{
    ...
    public function fields(Request $request)
    {
        return [
            Boolean::make('Has Comments'),
            Text::make('Title'),
            Text::make('Subtitle')->nullable(),
            Number::make('Number of comments allowed'),
            NestedForm::make('Comments')->displayIf(function ($nestedForm, $request) {
                return [
                    [ 'attribute' => 'has_comments', 'is' => true ],
                    [ 'attribute' => 'title', 'isNotNull' => true ],
                    [ 'attribute' => 'subtitle', 'isNull' => true ],
                    [ 'attribute' => 'title', 'includes' => 'My' ],
                    [ 'attribute' => 'number_of_comments_allowed', 'moreThanOrEqual' => 1 ],

                    // Integration for nova booleanGroup field
                    [ 'attribute' => 'my_multiple_checkbox', 'booleanGroup' => 'the_checkbox_key_to_target' ],
                ];
            })
        ];
    }
}

The package will then add those conditions and dynamically update your form as you fill the fields. The available rules are:

  • is
  • isNot
  • isNull
  • isNotNull
  • isMoreThan
  • isMoreThanOrEqual
  • isLessThan
  • isLessThanOrEqual
  • includes
  • booleanGroup

Add a minimum or a maximum number of children

For instance, if you want every user to have at least 3 posts and at most 5 posts, simply use:

NestedForm::make('Posts')->min(3)->max(5),

Please note that the package automatically detects whether the relationship excepts many children or a single child, and sets the maximum value accordingly.

When creating a new user, 3 blank posts will be displayed. If you reach the maximum number of posts, the "Add a new post" button will disappear.

Set the default open/collapse behavior

If you want the nested forms to be opened by default, simply use:

NestedForm::make('Posts')->open(true),

Modify the default heading

You can modify the default heading using the heading() method. You can use the helper method wrapIndex() to add the current child index to your header.

NestedForm::make('Posts')->heading(NestedForm::wrapIndex() . ' // Post'),

You can also add any attribute of the current child into your heading using the helper method wrapAttribute().

NestedForm::make('Posts')->heading(NestedForm::wrapIndex() . ' // ' . NestedForm::wrapAttribute('title', 'My default title')),

Modify the index separator

You can modify the default index separator using the separator() method when you have nested forms (e.g. 1. Post, 1.1. Comment, 1.1.1. Like).

NestedForm::make('Posts')->separator('\'),
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].