Jump to content

Best way to do a fixed count, repeated group of fields?


cst989
 Share

Recommended Posts

Hi, I'm using a repeater in the following manner:

I have set the minimum items to 5, and the maximum number of items to 5. I basically just want to loop through a few fields five times.

But I feel like I'm really forcing the repeater to do something it's not really meant for by doing this. A table would look and feel better, but as far as I know can't be fixed to x rows/pre-populated.

image.thumb.png.d09a209f0111195e4021df03d9756a84.png

 

Also there's a technical problem with this. Repeater rows do not seem to save unless you change something. So if I make a new page with the fields above and hit save, no data is actually available for the field. In my screenshot you can see that items #1 and #5 have saved because the type has been changed to 2 - they're solid and don't say "New" anymore. Also item #4 has saved because the type was changed and changed back. But #2 and #3 won't ever save unless you change the value.

If there's not a better suggestion for the approach in general - I would appreciate any technical support in forcing each row to save!

Link to comment
Share on other sites

That looks great! If "show all rows" is selected, and you open and save a fresh page with that field, does it actually save rows for you to iterate through? Per my issue at the end of my first post -- it caused me some issues with repeater

Link to comment
Share on other sites

7 hours ago, cst989 said:

If "show all rows" is selected, and you open and save a fresh page with that field, does it actually save rows for you to iterate through?

I believe so, but the simplest thing would be to try it and see.

Link to comment
Share on other sites

  • 3 weeks later...

I didn't get as far as checking if a table field would save the rows when they were new, because unfortunately table doesn't offer as many options that I needed, like a default option on selector, or the ability to show/hide fields 

I ended up sticking with the repeater matrix but forcing the repeater to publish on save. I tried the following, it worked at first but then it started creating database errors....

$this->addHookAfter("Pages::saveReady", function (HookEvent $event) {
    $page = $event->arguments("page");
    if(!($page->hasField("featured_articles"))) return;
    foreach($page->featured_articles as $item) {
        $item->of(false);
        $item->status("published");
        $item->save();
    }
});

now I think I'm just going to create 5 separate fields of "fieldset (page)" type ? 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...