F
Filamentโ€ข15mo ago
Chriis

[object Object] shows as default in Repeater->simple(TextInput)

Hi, like the title say ... I have no idea why its doing that. Its a repeater->simple() which is into a getSteps() method, into a Create{ResourceName} class (extends CreatedRecord) Help would be really appreciated ๐Ÿ™‚
No description
48 Replies
BlackShadow
BlackShadowโ€ข15mo ago
I feel like you are using it wrong:
Repeater::make('answers')
->simple(TextInput::make('title')->required())
->relationship('answers')
->columnSpanFull()
->defaultItems(0)
->hiddenLabel(),
Repeater::make('answers')
->simple(TextInput::make('title')->required())
->relationship('answers')
->columnSpanFull()
->defaultItems(0)
->hiddenLabel(),
Chriis
ChriisOPโ€ข15mo ago
It can't be used for creating a resource ? Like I need to have a relationship filling the Repeater ?
BlackShadow
BlackShadowโ€ข15mo ago
You don't have to use relationship The repeater component allows you to output a JSON array of repeated form components. We recommend that you store repeater data with a JSON column in your database. Additionally, if you're using Eloquent, make sure that column has an array cast.
Chriis
ChriisOPโ€ข15mo ago
Ok, so I'm not using it wrong
BlackShadow
BlackShadowโ€ข15mo ago
Maybe you need to cast the column to JSON or something ๐Ÿค”
Chriis
ChriisOPโ€ข15mo ago
I have a SheetResource, which can have a json array of objectives. So in the SheetResource creation form I have this Repeater->simple() which take one objective by line.
BlackShadow
BlackShadowโ€ข15mo ago
Show code
Chriis
ChriisOPโ€ข15mo ago
No description
No description
Chriis
ChriisOPโ€ข15mo ago
For visualizing where is this Repeater, I have described it in the post description
BlackShadow
BlackShadowโ€ข15mo ago
Remove the cast try again
Chriis
ChriisOPโ€ข15mo ago
Same ... And also, the context doesn't matter here, since I have the same problem anywhere I put a Repeater->simple()
BlackShadow
BlackShadowโ€ข15mo ago
Let me try
Chriis
ChriisOPโ€ข15mo ago
Ok
BlackShadow
BlackShadowโ€ข15mo ago
// ProfileResource
Forms\Components\Repeater::make('examples')
->simple(Forms\Components\TextInput::make('name'))
->columnSpanFull(),
// ProfileResource
Forms\Components\Repeater::make('examples')
->simple(Forms\Components\TextInput::make('name'))
->columnSpanFull(),
// Migration
$table->json('examples')->nullable(); // ["asdasd", "asdad", "asdad"]
// Migration
$table->json('examples')->nullable(); // ["asdasd", "asdad", "asdad"]
// Profile Model
protected $casts = ['examples' => 'array'];
// Profile Model
protected $casts = ['examples' => 'array'];
BlackShadow
BlackShadowโ€ข15mo ago
Test data
BlackShadow
BlackShadowโ€ข15mo ago
Just works ๐Ÿ˜›
Vp
Vpโ€ข15mo ago
Check in create, not edit.. In edit working fine, in create it shows like OP
BlackShadow
BlackShadowโ€ข15mo ago
ooh You are right Creating works too? But if you dont have ->defaultItems(0) it shows Object object indeed. ๐Ÿค”
BlackShadow
BlackShadowโ€ข15mo ago
Vp
Vpโ€ข15mo ago
Yes this one prevent this error tho.. so @Chriis you can put "defaultItems" for time being.. haha
BlackShadow
BlackShadowโ€ข15mo ago
Thats what i said squint
Chriis
ChriisOPโ€ข15mo ago
Yeah it works, but I thought we could have an empty input ๐Ÿ˜ฆ But no problem I'm going to use this
BlackShadow
BlackShadowโ€ข15mo ago
I don't think it can ever be empty. Make sure to make a bug report if there is not one already.
Chriis
ChriisOPโ€ข15mo ago
Well if not it should be clearly displayed in the documentation Because its confusing
BlackShadow
BlackShadowโ€ข15mo ago
You can actually, my bad. Just not for relationships i think ๐Ÿ‘
Vp
Vpโ€ข15mo ago
I'll check and if I can fix I'll create a PR and inform here again
Chriis
ChriisOPโ€ข15mo ago
Ok thx a lot
Vp
Vpโ€ข15mo ago
GitHub
Simple repeater [Object Object] fix by valpuia ยท Pull Request #8845...
Changes have been thoroughly tested to not break existing functionality. New functionality has been documented or existing documentation has been updated to reflect changes. Visual changes are ex...
Chriis
ChriisOPโ€ข15mo ago
Nice, but what happened to the PR ? It has been closed for your remark on the documentation but you did actually fixed the "[Object Object]" bug in it right ?
BlackShadow
BlackShadowโ€ข15mo ago
Not sure why its closed
Chriis
ChriisOPโ€ข15mo ago
I think its because he also talk about the output of the repeater->simple() which is not like described in the documentation, and Dan is right about this. However, Dan missed the main topic of the PR which is the bugfix for "[Object Object]" and not the documentation "problem" ... ๐Ÿ˜‘
BlackShadow
BlackShadowโ€ข15mo ago
Maybe you can ping him ๐Ÿ‘€
Chriis
ChriisOPโ€ข15mo ago
@Dan Harrin
BlackShadow
BlackShadowโ€ข15mo ago
Or respond to the Ticket.
Dan Harrin
Dan Harrinโ€ข15mo ago
Theres not enough detail, i dont know what the problem is what does the data in the database look like
BlackShadow
BlackShadowโ€ข15mo ago
If you have a json column named examples and you just follow the docs:
Repeater::make('examples')
->simple(
TextInput::make('name')
->required(),
)
Repeater::make('examples')
->simple(
TextInput::make('name')
->required(),
)
When creating a new resource with that field it will show Object object See my example Im not sure what causes this but i tried to replicate hes issue and i got the same ๐Ÿ˜œ
Dan Harrin
Dan Harrinโ€ข15mo ago
so the issue is only to do with default() ? and its not an issue with data in the database being loaded back into the form
BlackShadow
BlackShadowโ€ข15mo ago
Only when creating i would say. Yea
Dan Harrin
Dan Harrinโ€ข15mo ago
well when creating, it saves into the database correctly so its a problem with default
BlackShadow
BlackShadowโ€ข15mo ago
Yea yea thats what i meant.
Dan Harrin
Dan Harrinโ€ข15mo ago
and this is why i closed it, that detail was not mentioned anywhere
BlackShadow
BlackShadowโ€ข15mo ago
I see Im not sure what VP mentioned and if he actually fixed it.
Dan Harrin
Dan Harrinโ€ข15mo ago
well that code affects both defaults and Edit so i will need to test it myself
BlackShadow
BlackShadowโ€ข15mo ago
Alrighty ๐Ÿ™‚ Let me know if you need any more info ๐Ÿ˜›
Vp
Vpโ€ข15mo ago
Will try to look more..
Marcellin
Marcellinโ€ข14mo ago
Is there a fix yet? For the meantime set ->default([""]) (array with an empty element)
Chriis
ChriisOPโ€ข14mo ago
Idk if @Vp had time to look more into it, I'm also waiting for it ๐Ÿ˜ฆ
Vp
Vpโ€ข14mo ago
Sorry guys, i cannot figure out the root problem, i just submitted an issue https://github.com/filamentphp/filament/issues/8874 This is another trick instead of default item 0
Repeater::make('examples')
->simple(
TextInput::make('examples.name')
->required(),
)
Repeater::make('examples')
->simple(
TextInput::make('examples.name')
->required(),
)
GitHub
[object Object] display on simple repeater ยท Issue #8874 ยท filament...
Package filament/filament Package Version 3.0.67 Laravel Version 10.26.2 Livewire Version 3.0.5 PHP Version 8.2 Problem description While using below code, it shows [object Object] in input field w...
Want results from more Discord servers?
Add your server