GithubHelp home page GithubHelp logo

nova-simple-repeatable's Introduction

Nova Simple Repeatable

Latest Version on Packagist Total Downloads

This Laravel Nova package allows you to create simple horizontal rows of fields that the user can add/remove.

Requirements

  • php: >=8.0
  • laravel/nova: ^4.0

Features

A Laravel Nova simple repeatable rows field.

Screenshots

Form page

Installation

Install the package in to a Laravel app that uses Nova via composer:

composer require outl1ne/nova-simple-repeatable

Usage

use Outl1ne\NovaSimpleRepeatable\SimpleRepeatable;

public function fields(Request $request) {
    SimpleRepeatable::make('Users', 'users', [
        Text::make('First name'),
        Text::make('Last name'),
        Email::make('Email'),
      ])
      ->canAddRows(true) // Optional, true by default
      ->canDeleteRows(true), // Optional, true by default
}

Localization

The translations file can be published by using the following publish command:

php artisan vendor:publish --provider="Outl1ne\NovaSimpleRepeatable\SimpleRepeatableServiceProvider" --tag="translations"

You can then edit the strings to your liking.

Credits

License

Nova Simple Repeatable is open-sourced software licensed under the MIT license.

nova-simple-repeatable's People

Contributors

eimantaaas avatar emilianotisato avatar ganyicz avatar kasparrosin avatar marttinnotta avatar mlopezsti avatar tarpsvo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

nova-simple-repeatable's Issues

DependsOn does not work in Nova 4.17.1

Nova 4.17.1

My code:
SimpleRepeatable::make(__('app.links_column'), 'json_content', [ Text::make(__('app.item_name'), 'name'), Text::make(__('app.link'), 'link'), Boolean::make(__('app.is_column_heading'), 'is_heading'), ]) ->dependsOn('type', function (SimpleRepeatable $field, NovaRequest $request, FormData $formData) { if (! \App\Models\Card::display_links_array_fields($formData->type)) { $field->hide(); } }),

Error mesage: Method Laravel\Nova\Http\Controllers\CreationFieldController::sync does not exist.

When I removed DependOn, field is working

[Help wanted] [Possible-bug] How to work with nova-translatable

I'm trying to make my repeater field translatable, but once i save it stays empty and gives a console error

Packages used
optimistdigital/nova-translatable: 1.12
outl1ne/nova-simple-repeatable: 1.4.3
laravel/nova: 3.32

Code

Migration

Schema::table('projects', function (Blueprint $table) {
    $table->json("items")->nullable();
});

model

 public $translatable = [
        'items',
    ];

nova-resource

 SimpleRepeatable::make(__('Bullet points'), 'items', [
                Text::make(__('Bullet point'), 'bullet_point'),
            ])->translatable(),

console Exception, and no items or item title to be found
image

Prepopulate using withMeta or equivalent

Hello,

Is there any way to pre-populate a set of rows using withMeta or the equivalent? I've updated to Nova 4 and can no longer use 64robots/nova-fields, which allowed me to do that.

Thanks!

* Missing on required fileds

When setting fields as required * is missing from the field label.

Example:

image

image

Field Text should have red * to indicate that field is required

Store SimpleRepeatable as JSON attribute not working.

I am using SimpleRepeatable under Flexible Content Layout(https://github.com/whitecube/nova-flexible-content). Its generates the fields but not able to save it successfully. I think issue is SimpleRepeatable not able to store under JSON attribute.

Flexible::make('Sub Regions', 'sub_regions')
->addLayout('Sub Region', 'sub_region', [
Text::make('Title'),
SimpleRepeatable::make('Charges', 'charges', [
Text::make('Weight From', 'weight_from')
->required(true),
Text::make('Weight To', 'weight_to')
->required(true),
])
->fullWidth()
->button('Add Sub Region'),
]),

Able to create one JSON attribute and save SimpleRepeatable JSON under it? Here "Charges" attribute not generated.

image show wrong

  • Laravel Version: 10.28.0
  • Nova Version: 4.27.14
  • PHP Version: 8.1.22
  • Database Driver & Version: mysql 8.0.34
  • Operating System and Version: Ubuntu 20.04.6 LTS(base on macOS 14 and homestead)
  • Browser type and version: Firefox 118.0.2

PHP Code:

SimpleRepeatable::make(__('orderGoods'), 'orderGoods', [
    Image::make(__('thumb'), 'thumb')->readonly(),
    Text::make(__('goods_id'), 'goods_id')->readonly(),
    Text::make(__('goods_name'), 'goods_name')->readonly(),
    Text::make(__('market_price'), 'market_price')->readonly(),
    Text::make(__('number'), 'number')->readonly(),
    Text::make(__('total_price'), 'total_price')->readonly(),
    ])
    ->canAddRows(false) // Optional, true by default
    ->canDeleteRows(false)
    ->readonly()->onlyOnForms(),

on edit page,only show a svg image,not show the image.

WX20231018-085218@2x

Dark theme styling

I think it would be nice if the list view has a different styling on dark mode. This is what is currently looks like.

image

Field don't support show options

            SimpleRepeatable::make(__('Photos'), 'photos', [
                Text::make(__('Link'), 'link')
                    ->rules('required')
                    ->onlyOnForms(),

                Text::make(__('Link'), fn () => '<a href="/admin/resources/cities/4" class="no-underline font-bold dim text-primary">test</a>')
                    ->rules('required')
                    ->asHtml()
                    ->onlyOnDetail(),
            ]),
            

image

Date fields are not working

When adding a date field in a row, Nova throws an error:

local.ERROR: Date field must cast to 'date' in Eloquent model.

Because row entries ain't eloquent attributes, they can't be casted.

Translations bug

When using this package together with outl1ne/nova-translatable, it's working great but the languages is displayed in wrong order and default selected language is not the same as set in config, but in fields language is displayed from default language. And if you switch languages to default and then from default back to English (which was selected on load) it displays correct language.

Using the latest versions of repeatable, translatable and Nova.

Here are video recording to better understand the problem:

Screen.Recording.2023-05-29.at.12.41.09.mov

Validation Errors Issue

When you have roles attached to SimpleRepeatable Field anf you get a validation error that DOES NOT related to SimpleRepeatable filed, then you get an error

image

TypeError: Cannot read property '0' of null
Seems in case we have validation error, it tries to get first validation error. but as that validation error belongs to another filed, it tries to get first item from NULL, and that brakes the JS code.
In this case Sorting and "Add Row" don't work anymore, and also the data can't be saved anymore, even when validation error is fixed.

TypeError: Cannot read properties of undefined (reading 'find')

This issue occurs when I use the update function. I add two lines and leave all the required fields empty in those two lines. Then, when I click submit, I get an error message saying that the necessary fields are not filled out. Finally, if I delete the second line, an error occurs.

version

  • nova: 4.26.5
  • nova-simple-repeatable: 2.2.1

error message

TypeError: Cannot read properties of undefined (reading 'find')
    at Proxy.getValidationKey (http://myserver/nova-api/scripts/simple-repeatable:2:34392)
    at http://myserver/nova-api/scripts/simple-repeatable:2:73351
    at Array.forEach (<anonymous>)
    at s (http://myserver/nova-api/scripts/simple-repeatable:2:73320)
    at Proxy.repeatableValidation (http://myserver/nova-api/scripts/simple-repeatable:2:73424)
    at Ee.run (http://myserver/vendor/nova/vendor.js?id=f249b9bf29d2374b7fa61636323b3851:2:1499936)
    at get value [as value] (http://myserver/vendor/nova/vendor.js?id=f249b9bf29d2374b7fa61636323b3851:2:1508813)
    at Object.get [as repeatableValidation] (http://myserver/vendor/nova/vendor.js?id=f249b9bf29d2374b7fa61636323b3851:2:1531633)
    at http://myserver/nova-api/scripts/simple-repeatable:2:76090
    at ni (http://myserver/vendor/nova/vendor.js?id=f249b9bf29d2374b7fa61636323b3851:2:1527877)

How to center content??

I cannot seem to be able to align anything, the table headers are centered but the rows are not.

I have tried all of the following with no results:
DateTime::make('Start Date')->textAlign('center');

Issue putting Nova Rating fields in a SimpleRepeatable field

I'm using Nova Rating package (https://github.com/nikaia/nova-rating-field) for fields inside of a SimpleRepeatable field. The edit page looks great, but on the detail page, the underlying values are displayed instead of the stars.

Further down on the same detail page, I am using the rating outside of a SimpleRepeatable, and the stars are displaying.

Working on the edit page:
image

Showing the underlying value on the detail page:
image

Further down the edit page:
image

Array to String Conversion

I set up the field as json, but when I save I get Array to String Conversion

What am I missing

public function fields(Request $request)
{
    return [
        
        SimpleRepeatable::make('Vacation Days', 'vacation_days', [
            Text::make('Name', 'name')->sortable(),
            Date::make('Starting Date', 'starts_at'),
            Date::make('Ending Date', 'ends_at'),
        ])->canAddRows(true)->canDeleteRows(true)


    ];
}

nested simplerepetable does not work

nested simple-repetable does not work correctly - losted values of nested simple-repetable

SimpleRepeatable::make('Test', 'test',
            [
                Text::make('Title'),
                Text::make('SubTitle'),
                SimpleRepeatable::make('List', 'list',
                    [
                        Text::make('Title'),
                    ]
                )->stacked(),
            ])

image
after save - list titles lost values

HasMany SQLSTATE[42S22]: Column not found

I've this relation:

HasMany::make(__('Answers'), 'answers', NumberReactionAnswer::class),

And this field works on index and edit:

            SimpleRepeatable::make(__('Answers'), 'answers', [
                Textarea::make(__('Answer'), 'content')->required()->rules('required')->rows(2),
                Number::make('Min')->default(-100)->required()->rules('required')->step(0.001),
                Number::make('Max')->default(100)->required()->rules('required')->step(0.001),
            ])
                ->canAddRows(true)
                ->canDeleteRows(true),

But if I want to save, I get this error message:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'answers' in 'field list'

Stacked Field in SimpleRepeatable

SimpleRepeatable::make('Step Groups', 'step_groups', [
    Stack::make('Name', [
        Text::make('Name', 'name'),
        Slug::make('Slug')->from('Name'),
    ]),
    Textarea::make('Value'),
    Textarea::make('Default')->nullable()
])->stacked(),

This returns the error:
Call to a member function all() on array

[2.2.0] Deleting a row leaves rows with a different row index than what is being submitted

SimpleRepeatable::make('Charges', 'charges',[
  Currency::make('Limit', 'limit')->rules(['required', 'integer', 'min:1', 'distinct'])->step(1),
  Currency::make('Charge', 'charge')->rules(['nullable', 'numeric']),
]),

Steps:

  1. With the above field on a form add 3 rows you will end up with inputs with correct indexes 0,1,2
  2. Submit the form with empty fields and you will get The charges.x.limit field is required on all 3 rows. This is expected.
image
{
    "message": "The charges.0.limit field is required. (and 2 more errors)",
    "errors": {
        "charges.0.limit": [
            "The charges.0.limit field is required."
        ],
        "charges.1.limit": [
            "The charges.1.limit field is required."
        ],
        "charges.2.limit": [
            "The charges.2.limit field is required."
        ]
    }
}
  1. Delete the first row

  2. Submit the form again with empty fields, only the first row shows The charges.1.limit field is required

image
{
    "message": "The charges.0.limit field is required. (and 1 more error)",
    "errors": {
        "charges.0.limit": [
            "The charges.0.limit field is required."
        ],
        "charges.1.limit": [
            "The charges.1.limit field is required."
        ]
    }
}

This is because the two rows have indexes 1 and 2 but the data being submitted for validation has indexes 0 and 1.

Translatable

Hello, I couldn't run it with nova-translatable package. Always empty resolving.

Multiple select merge bug

SimpleRepeatable::make('Admins', 'admins', [
    Select::make('Language', 'language')
        ->options(\App\Models\Language::all()->pluck('title', 'id'))
        ->searchable()
        ->fillUsing(fn ($request, $model, $attribute, $requestAttribute) => $model->{$attribute} = \App\Models\Language::find($request->language)->title),

    Select::make('User', 'user')
        ->options(\App\Models\User::select('id', 'name')->get()->pluck('id', 'name'))
        ->searchable(),
]),

image
image

After removing searchable method problem dissapears

jsonSerialize incompatible

Keep getting error: Return type of Outl1ne\NovaSimpleRepeatable\Row::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/task/vendor/outl1ne/nova-simple-repeatable/src/Row.php on line 68

Field dependsOn

I'd like to do something like this, but it doesn't seem to trigger anything...

SimpleRepeatable::make('Theme Templates', 'templates', [
    Select::make('Theme', 'theme_id')->displayUsingLabels()
        ->options(fn() => $this->team->themes->pluck('name','id')),
    Select::make('Template')
        ->dependsOn(['theme_id'],
            function (Select $field, NovaRequest $request, FormData $formData) {
                $field->options(Theme::find($formData->theme_id)->templates);
            }
        )
])->stacked(),

Redraw component from dependsOn function

Is there any way or even work-around to cause the component to update from within the dependsOn function? Let's say for example that the field is using data from a relationship model that is also selectable on the same resource. Is there a way to do it?

BelongsTo::make('product'),
SimpleRepeatable::make('Varieties', [
    Text::make('name),
    Number::make('percentage'),
])
   ->dependsOn('product', function(SimpleRepeatable $field, NovaRequest $request, Form $formData) {
       $product = Product::find($formData->product);
       $field->setValue($product->varieties->map(fn($p) => $p->only(['name', 'percentage'])->toArray());
       // Does not work :(
       // I also tried the following but does not work either
       $field->withMeta(['rows' => $product->varieties->map(fn($p) => $p->only(['name', 'percentage'])->toArray()]);
    }),

Perhaps it's only there to conditionally display the field?

Psalm InvalidArgument error

In nova abstract field exists annotation

/**
* @method static static make(mixed $name, string|\Closure|callable|object|null $attribute = null, callable|null $resolveCallback = null)
*/

I get error "Argument 3 of Outl1ne\NovaSimpleRepeatable\SimpleRepeatable::make expects callable|null" for next code

SimpleRepeatable::make('Images', 'images', [
    URL::make('Url'),
]),

File field is not working

When I try to save File, file is not saved.

            SimpleRepeatable::make('Súbory na stiahnutie', 'downloads', [
                Text::make('Názov', 'name')
                    ->rules(['required']),
                File::make('Súbor', 'file'),
            ]),
[{"file": [], "name": "Test"}]

Bug on layout in view field

Screenshot 2021-09-16 at 11 22 39

The view layout seems to be getting styles from the edit layout (.simple-repeatable>:nth-child(2)) which is making it ignore the width and throw off the layout compared to fields around it.

[Help Wanted]: Repeatable Row display default

Is there any way to show one row by default when we create? Currently, it only displays the 'Add Row' button for the very first time.
So, is there any way to show one row when page load by default every time along with the 'Add Row' button?
Screenshot (344)

validation of fields

Validation of fields contained in the repeatable field is not working. Is that correct?

Default value

Hi all,

How can set default value ?

Thanks in advance

Save data as simple JSON array?

Is it possible with this field to save the field data as an array, in circumstances where there is just one field in the repeatable?

I have a SimpleRepeatable that contains just one Text field (in this case, named pattern) and when saved to my model, the JSON in the database is: [{"pattern": "12345"},{"pattern": "67890"}]

Is it possible to have it save it as just an array, i.e.: ["12345","67890"] ?

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.