Jump to content

Repeatable Fields


ryan

Recommended Posts

I've been working on making repeatable fields for ProcessWire for a couple weeks and actually now have it nearly ready. I need to do some more testing before releasing it, but wanted to give you a little preview.

(please view the full screen version for better quality)

Accessing repeatable fields from the API is super-easy. They are fully searchable/selectable with the API just as easily as with any other fields. So if you wanted to find all pages that had a buildings field with a floors value of 50 or more, you'd do this, for example:

$pages->find("buildings.floors>=50"); 

Lets say you are on the page with a 'buildings' field and you want to print out all the building names and number of floors. It works exactly the same as page references:

foreach($page->buildings as $p) {
 echo "<p>{$p->building_name}</p> has {$p->floors} floors.</p>";
}
  • Like 10
Link to comment
Share on other sites

Awesome! Yeah first! O0

Now going to look at video.... :P

Edit:

Looks really great! Thank you for this preview! For sure very useful.

Now my question. Would it be any way possible to have to be able define multiple "block" templates (with different fields each) for the repeater field? Then when adding a new item, it would ask for the block template to select first. Pretty much the same as it is now, just with variable templates. I can imagine it would require something complete different concept/codewise.

It's just what I kinda "expected" from (the) repeatable page element, so I don't have to use child pages anymore. It can be very handy to be able to define "blocks" that can be chosen from, to build a page. TItle, Video, Text-Image, Linklist, Text. Do you see a good way to add such "variable blocks" feature to PW through a module, much similar like this one? Maybe they're also just invisible childpages that are editable and sortable via the parent page's block field. Just blah blah, I don't really know what all need to be considered. Have you implemented this repeater using hidden pages?

  • Like 3
Link to comment
Share on other sites

Thanks for checking it out, glad you guys like it so far!

Soma what you described is quite similar to how this system works. It literally is creating a system template behind-the-scenes, and each repeatable element is a page. You can have as many repeatable fields, and repetitions of those repeatable fields, as you want. You can even stack them (repeaters in repeaters) though I don't think I'd want to. :)

The pages are hidden outside of the site structure, so you won't see where they are at first. Likewise, the templates are hidden as system templates, so you won't see them in your usual development. But if you want to put in a template file to provide the rendering capability for the items, you can... enabling you to do something like $building->render();

I'm working on a 'detach' capability that lets you move the repeater template and parent into your site structure, should you want to. But this 'detach' capability won't appear in the first version. The reality is, repeaters are more approachable if you don't have to see the technical details of how they work, right in your site structure. But the fact that they can be part of your site structure opens a lot of possibilities, so that's why I've already started work on making them detachable ... it'll make building large sites a lot easier if you can create 100 pages on 1 screen, for example.

Link to comment
Share on other sites

Great work Ryan! This will make it so much more intuitive for editors in some situations!

And I also think it will bring more people to PW, as it was obviously one of the most requested features.

Link to comment
Share on other sites

Ryan, that's awesome and extremely useful. Thanks.

Just an idea and I don't know how feasible it is, but wouldn't it make since to have repeating fields already built into the core processwire fields? For example, when adding a text field, image field, etc, a user would have an option for "make repeatable".

Link to comment
Share on other sites

Andrew, I also thought of that. But since you would have to program your template to deal with them anyway, I don't think it would be any easier to use a system of that kind instead of this one.

Link to comment
Share on other sites

Ryan, I love it!

Soma, I absolutely get what’s your point. Especially for editors it would be a very comfortable solution to deal with repeatable elements of different templates. Maybe their should be a kind of helper field type, that just allows you to manage a page’s child pages as repeatable elements, so editors don't have to deal with creating child pages manually.

Its input field setup in the page edit process would look just like ryan’s here, showing blocks with the child pages’ fields. The editor could choose from the allowed templates for new child pages. And in templates the field would directly provide the page array like in repeatable elements. Of course it just would be a kind of shortcut for stuff that could be done manually already.

Right now I’m working on a project, where such a thing would be pretty useful.

  • Like 2
Link to comment
Share on other sites

This looks awesome Ryan amazing work!

Its input field setup in the page edit process would look just like ryan’s here, showing blocks with the child pages’ fields. The editor could choose from the allowed templates for new child pages. And in templates the field would directly provide the page array like in repeatable elements.

Totally agree with this :)

Link to comment
Share on other sites

This looks amazing Ryan! Thanks for creating a video showing the functionality too - it makes things very clear.

I'm personally glad to see that you haven't just gone the Drupal route of adding a simple checkbox on a single field creation for 'make repeatable'. This is an easy way to do things but your approach allows for repeatable fieldsets or groups of fields which is much more powerful.

Like others here - I can't wait to see this in a release of PW.

Link to comment
Share on other sites

Great stuff, Ryan! ^-^

The funny thing is that I didn't think I would need repeatable fields... but after seeing the video I came up with several different uses of them in my current project. Obviously I didn't know what I was missing and/or what to expect of repeatable fields. :rolleyes:

/Jasper

Link to comment
Share on other sites

Thanks for all the great feedback! This module is ready now, but I feel like I need to give it a more thorough testing on this end so will probably aim to have it to you this weekend or early next week. I'm short on time today, but am hoping to catch up with all of the questions here tomorrow.

Link to comment
Share on other sites

I wanted to add that the idea behind the repeatable fields implementation came from Diogo and his post (below), as well as related posts from Apeisa, Adamkiss and Martinluff (and I may be missing others) sparked the direction used in the new repeatable fieldtype. While a little different than what he mentioned, Diogo's original post, and follow-up posts are what got the ideas and momentum towards this direction going for the current implementation:

http://processwire.c...ndpost__p__4519

Initially I'm just trying to get a reasonably simple implementation of repeatable fields going, but down the road we'll expand to broaden the possibilities consistent with peoples' needs... perhaps with pagination and more. Though admittedly, terms like pagination within a field make me wonder if we're going too far. :) But I've started to revisit some code in the FieldtypeRepeater module based on some feedback here, working towards giving you more page management possibilities with it. But don't expect too much here, this will just be a beta test version 1 and it's not going to perform any miracles. And like with anything new, I'm sure there will be bugs to uncover as well.

Repeatable fields like this do seem to open a lot of new possibilities. I think part of that is just that we've not had them quite like this before (at least in PW), and it seems like a whole new dimension to explore. But while you could apply repeatable fields like this to all kinds of uses, I don't necessarily think we should be doing that. They will be great for some things, but they will also be tempting to use in places where they really shouldn't (I've already had to restrain myself). These repeatable fields with all kinds of possibilities will blur the line on that and demand more discipline. I think that like every page is viewed at it's own URL, it should also be edited at it's own URL (in most situations). But for repetitive data that may use a page + template by convenience rather than by need--repeaters will be perfect. I just don't want to see people turn their sites into spreadsheets. :) I personally will be using them on only half of sites that I build (I estimate). But I can't wait to get this out for you all to try and see where it might help to simplify tasks and open new possibilities. I think I've only scratched the surface with my own testing here, so this fieldtype will continue to evolve as your needs do. Thanks for all the great ideas and interest in this.

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
  • Recently Browsing   0 members

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