Jump to content


Photo

Repeatable Fields


  • Please log in to reply
263 replies to this topic

#1 ryan

ryan

    Reiska

  • Administrators
  • 7,797 posts
  • 6573

  • LocationAtlanta, GA

Posted 14 February 2012 - 04:43 PM

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>";
}


#2 Soma

Soma

    Hero Member

  • Moderators
  • 5,057 posts
  • 3823

  • LocationSH, Switzerland

Posted 14 February 2012 - 04:50 PM

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?

@somartist | modules created | support me, flattr my work flattr.com


#3 apeisa

apeisa

    Hero Member

  • Moderators
  • 3,156 posts
  • 1707

  • LocationVihti, Finland

Posted 14 February 2012 - 05:20 PM

That is amazing stuff, looks so good!

Now back to coding everyone...

#4 ryan

ryan

    Reiska

  • Administrators
  • 7,797 posts
  • 6573

  • LocationAtlanta, GA

Posted 14 February 2012 - 05:44 PM

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.

#5 Marty Walker

Marty Walker

    Sr. Member

  • Members
  • PipPipPipPip
  • 476 posts
  • 274

  • LocationKatoomba, AU

Posted 14 February 2012 - 07:06 PM

Ryan,

This is more that I had hoped for when this feature was mentioned a while ago. Outstanding work. Will this makes it's way into PW 2.2 or future versions?

Regards
Martin

#6 diogo

diogo

    Hero Member

  • Moderators
  • 2,897 posts
  • 2303

  • LocationPorto, Portugal

Posted 14 February 2012 - 07:40 PM

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.

#7 AnotherAndrew

AnotherAndrew

    Sr. Member

  • Members
  • PipPipPipPip
  • 168 posts
  • 27

Posted 14 February 2012 - 08:05 PM

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".

#8 diogo

diogo

    Hero Member

  • Moderators
  • 2,897 posts
  • 2303

  • LocationPorto, Portugal

Posted 14 February 2012 - 08:17 PM

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.

#9 fnode

fnode

    Jr. Member

  • Members
  • PipPip
  • 17 posts
  • 3

Posted 15 February 2012 - 12:49 AM

Thank you, Ryan! :o

#10 fenton

fenton

    Full Member

  • Members
  • PipPipPip
  • 69 posts
  • 23

Posted 15 February 2012 - 01:05 AM

truly awesome! :) thanks Ryan

#11 Oliver

Oliver

    Sr. Member

  • Members
  • PipPipPipPip
  • 134 posts
  • 27

  • LocationBasel, Switzerland

Posted 15 February 2012 - 04:29 AM

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.

#12 almonk

almonk

    Jr. Member

  • Members
  • PipPip
  • 41 posts
  • 6

Posted 15 February 2012 - 04:57 AM

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 :)

#13 tsd

tsd

    Jr. Member

  • Members
  • PipPip
  • 24 posts
  • 4

Posted 15 February 2012 - 05:35 AM

Awesome! That's what i was waiting for :)
Can't wait for you to publish it

#14 raydale

raydale

    Distinguished Member

  • Members
  • PipPipPipPip
  • 118 posts
  • 64

Posted 15 February 2012 - 05:55 AM

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.

#15 Michael Murphy

Michael Murphy

    Distinguished Member

  • Members
  • PipPipPipPip
  • 101 posts
  • 66

  • LocationBasel, Switzerland

Posted 15 February 2012 - 09:25 AM

I missed this little Valentines day surprise yesterday :)

Very excited - this is going to be very useful - Thanks Ryan!

#16 formmailer

formmailer

    Sr. Member

  • Members
  • PipPipPipPip
  • 263 posts
  • 46

  • LocationHudiksvall, Sweden (but originally from The Netherlands)

Posted 15 February 2012 - 02:18 PM

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. ::)

/Jasper

#17 ryan

ryan

    Reiska

  • Administrators
  • 7,797 posts
  • 6573

  • LocationAtlanta, GA

Posted 15 February 2012 - 05:07 PM

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.

#18 diogo

diogo

    Hero Member

  • Moderators
  • 2,897 posts
  • 2303

  • LocationPorto, Portugal

Posted 15 February 2012 - 05:11 PM

This is great Ryan! I'm dying to test it :)

#19 pers0n

pers0n

    Jr. Member

  • Members
  • PipPip
  • 35 posts
  • 2

Posted 15 February 2012 - 06:55 PM

Cool, I could use these for slideshows for sure. :)

Each repeatable item doesn't link to its own content does it? I know we could add a link to another page, but I guess I didnt understand it 100% and probably wont until I play with it.

#20 nikola

nikola

    Sr. Member

  • Members
  • PipPipPipPip
  • 233 posts
  • 137

  • LocationZagreb, Croatia

Posted 16 February 2012 - 03:51 AM

Ryan, this is great news! Now we can extend PW further more. Thanks!
Check out my ProcessWire admin themes: Futura Remixed Admin Theme / Moderna Admin Theme / Futura Admin Theme




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users