Git Product home page Git Product logo

nova-inline-text's Introduction

Nova Inline Text

Version Total Downloads License

This package lets you edit text fields directly on your resources pages.

Installation

composer require pdmfc/nova-inline-text

Usage

use Pdmfc\NovaFields\InlineText;

//...

public function fields()
{
    return [
        InlineText::make('Name'),
    ];
}

Making it editable

By default, this field behaves like a regular text field. To be able to edit it on the index page, use the inlineOnIndex() method:

public function fields()
{
    return [
        InlineText::make('Name')
            ->inlineOnIndex(),
    ];
}

Basic usage

This method also accepts a closure with the current request if you want to make it editable dynamically:

public function fields()
{
    return [
        InlineText::make('Name')
            ->inlineOnIndex(function (NovaRequest $request) {
                return $request->user()->isAdmin();
            }),
    ];
}

Updating field value

The default trigger to save the value is by pressing the Enter key (keyup.enter). If you wish to use a different event trigger to update the value you can use the saveOn() method that accepts an argument corresponding to a javascript event:

public function fields()
{
    return [
        InlineText::make('Name')
            ->inlineOnIndex()
            ->saveOn('blur'),
    ];
}

Key event modifiers

You can also specify the key event modifier:

public function fields()
{
    return [
        InlineText::make('Name')
            ->inlineOnIndex()
            ->saveOn('keyup.shift'),
    ];
}

Refreshing resource table

When saving the current field value, it will not refresh the table. If you need this functionality, use the refreshOnSaving() method:

public function fields()
{
    return [
        InlineText::make('Name')
            ->inlineOnIndex()
            ->refreshOnSaving(),
    ];
}

⚠️ Caveats

  • When updating the field, make sure you add the sometimes validation rule to the rest of the fields that are required:

    Text::make('Email')
        ->rules('required', 'email')
        ->updateRules('sometimes') // Add these method call and validation rule to the fields that are required

How to contribute

  • clone the repo
  • on composer.json of a laravel nova application add the following:
{
    //...

    "require" {
        "pdmfc/nova-inline-text: "*"
    },

    //...
    "repositories": [
        {
            "type": "path",
            "url": "../path_to_your_package_folder"
        }
    ],
}
  • run composer update pdmfc/nova-inline-text

You're now ready to start contributing!

nova-inline-text's People

Contributors

joaopaulolndev avatar skoyah avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

nova-inline-text's Issues

Inline update on index deletes values from Currency field when not read only

  • Laravel Version: #.#.#
  •     "laravel/framework": "^8.0",
    
  • Nova Version: #.#.#
    "laravel/nova": "^3.10",
  • PHP Version: #.#.#
    "php": "^7.4",

Description:

When a Currency field is used and another field is used with inline-text->updateOnIndex()
the value of the currency field is not set on the record when saved but is updated to null.

Detailed steps to reproduce the issue on a fresh Nova installation:

Create a test nova resource with the following fields

public function fields(Request $request)
{
    return [
        ID::make(__('ID'), 'id'),
        Currency::make('CPL', 'cost_per_lead')
        InlineText::make('Leads', 'qualified_leads_count')
            ->inlineOnIndex(),
];

}

I've added updateRules('sometimes') on CPL with no changes - it isn't a required field.

If the CPL data field is not nullable it generates a MySQL error on update - if it is nullable it is set to null

In the same example if you replace Currency with Number it works normally.

If you make Currency read only it works normally.

If you try and hack it by using two fields and onlyOnForms/ExceptOnForms to make it still is updated to null.

Update field triggers 422 validation error

Hi,

I'm trying to use your plugin, but I get this error message; 422.

{message: "The given data was invalid.",…}
errors: {operation: ["The operation field is required."], producer: ["The producer field is required."],…}
consumer: ["The consumer field is required."]
operation: ["The operation field is required."]
producer: ["The producer field is required."]
message: "The given data was invalid."

Here is the definition of my resource:

    public function fields(Request $request)
    {
        return [
            ID::make()->sortable(),
            BelongsTo::make('Opération', 'operation', 'App\Nova\Operation'),
            BelongsTo::make('Producteur', 'producer', 'App\Nova\User'),
            BelongsTo::make('Consommateur', 'consumer', 'App\Nova\User'),
            Date::make('Début', 'date_ini')->required()->firstDayOfWeek(1),
            Date::make('Fin', 'date_end')->required()->firstDayOfWeek(1),
            InlineText::make('Prix de vente du kWh ( unité )', 'kwh_price')
                ->inlineOnIndex(function (NovaRequest $request) {
                    return $request->user()->isSuperAdmin();
                })->required(),
//            Currency::make('Prix de vente du kWh ( unité )', 'kwh_price')->required(),
        ];
    }

Error 422

Hi! I'm getting error 422. Any idea how to fix it?

Save on blur

The default behaviour to save the value is by pressing the enter key.

Users should have to possibility to define if the value should be saved on the blur event

Add validation caveat to the docs

When updating the field, the documentation should specify that the other fields should have the validation rule:

Text::make('Email')
    ->rules('required', 'email')
    ->updateRules('sometimes'),

error message of validation

It always return Error: Request failed with status code 422 to the user.
Would it be possible to return the validation error message ?
image

image

Relationship Integration

Your package is nicely working for inline edit for the Resource fields.
It will be great if the same package will work for pivot fields.

Issue- Actually when I use InlineText on the pivot field it gives a success message('Value updated') on updating the value. But when I refreshed the page and cross-checked in the database, I found that the value is not updated in DB.

Thanks!

Screenshot 2020-06-04 at 7 59 40 PM

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.