outl1ne / nova-simple-repeatable Goto Github PK
View Code? Open in Web Editor NEWA Laravel Nova simple repeatable rows field.
License: MIT License
A Laravel Nova simple repeatable rows field.
License: MIT License
When clicking the delete icon on the right hand side for any row, the first item in the repeatable list is removed
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.
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?
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)
];
}
when adding belongs to link got undefined with number
Hi all,
How can set default value ?
Thanks in advance
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!
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"]
?
I'm having multiple SimpleRepeatable fields on the same page and each one has a validation rules.
But the validation is only being applied for the first SimpleRepeatable field.
Validation of fields contained in the repeatable field is not working. Is that correct?
Hi,
Please add support for Nova 4
Regards
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"}]
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'
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.
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(),
When I use fillUsing validation rules for fields it no longer works, any possibility to make it work?
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(),
]),
After removing searchable
method problem dissapears
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.
Hi,
How can I set column used to sort repeatable block?
Regards
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
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
I upgrading to laravel 9, and using nova 3. Can't use nova 4 for now
https://github.com/keizah7/nova-simple-repeatable/commit/8218f37e3523a2f5c03866cd1d56575191981f2b
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:
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
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.
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.
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(),
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
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)
Hi!
Is there any way to set the maximum number of rows?
I saw the "maxRows" function, but it is not used by the front-end component.
Thanks!
Hello, I couldn't run it with nova-translatable package. Always empty resolving.
SimpleRepeatable::make('Charges', 'charges',[
Currency::make('Limit', 'limit')->rules(['required', 'integer', 'min:1', 'distinct'])->step(1),
Currency::make('Charge', 'charge')->rules(['nullable', 'numeric']),
]),
Steps:
The charges.x.limit field is required
on all 3 rows. This is expected.{
"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."
]
}
}
Delete the first row
Submit the form again with empty fields, only the first row shows The charges.1.limit field is required
{
"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
.
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');
I'm using hideWhenUpdating
on a field that's in SimpleRepeatable, but it did not hide the field, any ideas why?
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'),
]),
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.