This package lets you edit text fields directly on your resources pages.
composer require pdmfc/nova-inline-textuse Pdmfc\NovaFields\InlineText;
//...
public function fields()
{
return [
InlineText::make('Name'),
];
}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(),
];
}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();
}),
];
}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'),
];
}You can also specify the key event modifier:
public function fields()
{
return [
InlineText::make('Name')
->inlineOnIndex()
->saveOn('keyup.shift'),
];
}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(),
];
}-
When updating the field, make sure you add the
sometimesvalidation 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
- clone the repo
- on
composer.jsonof 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!
