Closed leoquijano closed 7 years ago
But... repeaters only affect the form's model and those fields should be jsonable (because the data is saved in that way in your database), in this case what you have to use are relations, I think that's exactly what you need.
About why it's loading the fields but empty, let's say that repeater
accepts an array as data, so it loads without error, try to use another type of field instead of repeater
in your example and will throw a non array exception.
edit: gonna try a lil trick for using 2 models in 1 form, it may work here!
It works!!!! Really it doesn't have much sense, but you can use a SINGLE field from another model in a repeater. It will store all data as JSON (still thinking what you need in this case is a relation, though).
Moar data here, only change the text field for a repeater and will work just fine
I had checked relations, but found them to be a bit too complex for that form. I thought repeaters were a simple way to do it. I guess I'll check again.
Exactly what do you want to acomplish? Maybe a json field could do the trick.
I have a Plan class, that has PlanTrustees (hasMany). So one plan can have N trustees.
Since we only require first & last names from trustees, a simple repeater would just add 2 text fields per trustee, and allow the customer to easily edit them without leaving that form or without using popups or other more complex UI.
Yeah, if you are not going to use those names and last names for another purpose it's the most simple way
Repeater only supports returning the result as an array at this point. It is possible for you to manipulate that array in something like formBeforeSave()
method override in your controller, so it will then populate and associate a related record.
Hi, I seek to implement a repeater like relation editor as well. Any code examples so far? @draftspunk Are there any plans to support something like this in future versions?
Hello, I have built a custom Model Trait HasManyJsonable that fetches hasMany relations into jsonable, and is able to sync the submitted form back into relations. It has a built in validation for repeater models.
It was quite a challenge, but in the end I had to implement those usecases in it:
It was quite a challenge, I would like to share this code but as I'm beginner in OctoberCMS the code isn't cleanest. But if anyone is interesting in making it into a shareable plugin, I'd love to share my code and help with refactoring. You can find me at github/idpsycho.
Hi,
I'm building a backend form with a repeater component. This is the $hasMany entry in the parent model (Plan):
Plugin\Models\Plan class:
And this is my YAML field configuration:
However, when I try to open an existing plan, I get N repeater items (as many as there are trustees), but they're all empty. And when a try to create a new plan (in this case with a Foo Bar trustee), I get this error:
The database tables are the usual:
I'm using the following versions of October CMS:
Is this feature working with relations?