Repeatable Fields
#22
Posted 16 February 2012 - 10:36 PM
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.
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.
#26
Posted 20 February 2012 - 12:42 PM
To install, just make sure your core is up-to-date, go to Admin > Modules and click 'Check for new modules'. It should find FieldtypeRepeater. Click install. Then create a new field and select 'Repeater' when it asks for the type.
Once you've added a repeater field to a page, you use the field from the API exactly as you would any other multi-page reference field (see the first post for an example).
I also want to note that if you have 'debug' mode enabled in your PW, the Repeaters Fieldtype is quite chatty (which you may or may not like). If debug mode is off, the fieldtype will do its job quietly.
#27
Posted 21 February 2012 - 11:43 AM
I have one more update that I put in the latest commit, though this applies to all fields, not just repeatable fields. This update enables you to create columns rather than just rows. You can now specify a width percent in any field's input settings (or use the columnWidth property on an inputfield from the API). Here's a screenshot of the new setting:
And here's the result (combined with a repeatable field). In the screenshot below, I've set building_name to have a width of 50%, floors to have a width of 25% and height to have a width of 25%:
Note that because this involves some stylesheet tweaks, this may not work on 3rd party admin themes right away. But I'll be happy to assist admin theme developers to add the necessary stylesheet tweaks to make this work.
#28
Posted 21 February 2012 - 12:12 PM
I was wandering what are the Repeater disadvantages compared to the children model "used before" related to Search and selectors?
Which template cache settings should to be used when updating Repeater field?
- Clear cache for current page only
- Clear cache for entire site *
- Clear cache ...
- ...
BTW. The Repeater (tested without the columnWidth) is working flawless.
#29
Posted 21 February 2012 - 12:53 PM
I was wandering what are the Repeater disadvantages compared to the children model "used before" related to Search and selectors?
While I've now had a lot of experience developing them, I've not yet had much experience using them. So I don't feel all that qualified to outline the cases where one should or shouldn't use them. However, my feeling is that repeaters are ideal for reasonably small collections of data that don't need their own page URL.
For instance, an office locations list or employee directory or something of that sort. Instances where you are going to be outputting the data in some table or list together, much like you edit them together. But I think the potential uses are much more broad than what I can think of right now, so this might be a better question for someone that's used matrix fields in EE or ACF in Wordpress, or a question for me to answer a couple months from now.
Search and selectors?
By default, the repeater pages are created somewhere outside of your site tree (actually in /processwire/repeaters/). Because they are hidden off below the admin, they aren't searchable as pages themselves, except by those with admin access. That's intentional. We don't want selectors matching these pages since they aren't being used in the context of pages (at least not by default). I will be adding an option to make them "detached" so you can place them wherever you want and actually use them as pages in your site should you want to. But that will be an option, not the default behavior.
Because they aren't searchable on their own by default, they have to be searched within the context of the page where they are used. So if you wanted to match all pages that had a 'buildings' having 40+ floors and a height field 800 or fewer feet, you'd do this:
$pages->find('buildings.floors>=40, buildings.height<=800');If you just wanted to match pages that had one or more buildings:
$pages->find('buildings.count>0');
$pages->find('buildings>0'); // this also works
Which template cache settings should to be used when updating Repeater field?
This doesn't matter unless you actually implement a template file for your repeater field. So you should be fine to clear the current page only, unless you prefer to clear the site for another reason.
If you want to implement a template file for your repeater, you create a file in your /site/templates/ named "repeater_[field name].php", i.e. in the case of the buildings field, it would be "repeater_buildings.php". That template file will receive a $page variable that is represents one 'buildings' record. So you could do something like this:
/site/templates/repeater_buildings.php
<?php
echo "<h2>{$page->building_name}</h2>";
echo "<p>{$page->floors} floors, {$page->height} feet</p>";
The template used by your page with a 'buildings' field could then do this:
/site/template/basic-page.php
foreach($page->buildings as $building) {
echo $building->render();
}
However, for a relatively simple case like this, I would probably not bother with creating a repeater_buildings.php template file, and instead just put it all in the basic-page.php template. But if you do use the approach of rendering repeater elements with their own template, then you would want to consider the cache. Rather, you'd probably want to avoid using the cache for your repeater_buildings template and instead just rely on the cache used by your basic-page template.
#30
Posted 21 February 2012 - 02:23 PM
BTW why didn't you use my slider field?
I'm testing it since yesterday and have had some issues, and some very strange issues.
- Thumbnails doesn't work. The edit links isn't found. Not sure whos responsible for this
- can't see the images in the RT from an image field in the repeater itself.
- When I add element, add image then delete it after save, after adding a new element the image is still in the there.
- I think the slider collumn field isn't saving, because I have to reinstall first? haven't tried yet.
Strange:
- When first time testing I did a repeater in a repeater and it doesn't seem to work. I removed the repeater and added new normal one text,slider,image,richtext. After that I experienced being showed the error by my own "soft edit page lock" module, after saving the page with repeater field, that the page is currently being edited by myself... Somehow does the session change or something? Now I only expereinced this 2-3 times and now since I created a new repeater without slider it haven't seen it yet again. Though I'll try test again see if I can reproduce.
@somartist | modules created | support me, flattr my work flattr.com
#31
Posted 21 February 2012 - 02:28 PM
#32
Posted 21 February 2012 - 02:56 PM
Thumbnails doesn't work. The edit links isn't found. Not sure whos responsible for this
Are you talking about the Thumbnails module by Antti? I haven't tried it out with the repeater yet. In order to work in a repeatable, a module would have to be okay with having multiple instances of itself on the page (whether in a repeatable or just used by more than one field). All the core field types are good in this area, as far as I know. One way to test it is to just create two separate fields that use the Thumbnails module, assign them both to the same template, and then attempt to edit a page with that template. If you get the same issue, then very likely there is some hard-coded ID attribute in one of the elements or something.
TinyMCE didn't take kindly to being in a jQuery sortable, so I had to make some adjustments for it. If you drag a repeater with a TinyMCE in it, you'll see I had to turn off TinyMCE for the field during the duration of the drag. But other than that, I've not run into problems with any other fieldtypes. If the Thumbnails module doesn't work now, I'm sure we'll be able to find a way to make it work.
can't see the images in the RT from an image field in the repeater itself.
I don't understand. What's an RT? (retweet?)
When I add element, add image then delete it after save, after adding a new element the image is still in the there.
Just confirmed -- this is a bug. If you only populate an image field (and not any other fields on the item) the page and image gets saved with ajax. The repeater doesn't get the opportunity to see a change was made. But I think this'll be an easy fix.
I think the slider collumn field isn't saving, because I have to reinstall first? haven't tried yet.
Can you clarify? Are you talking about the column width percent? You shouldn't have to reinstall anything. But make sure you are using the default admin theme, and hit reload once or twice to make sure you don't have JS or CSS files from an old version.
Somehow does the session change or something?
The repeater is basically rendering the Inputfields for multiple pages, so chances are that the soft lock is hooked into something that is getting called several times rather than just once. We can take a closer look at interactions with other modules, though I'm thinking I should work out any bugs with the Repeater module first.
Now I only expereinced this 2-3 times and now since I created a new repeater without slider it haven't seen it yet again.
Browser cache is always a possibility too.
I think there's much more precision than is needed in this context, i.e. the vast majority of people are going to set it to 25, 50, or 75%, so being able to set 51% is actually kind of annoying as you have to nudge it into the number you want. Maybe it could even just be 1, 2, 3, or 4 (it assumes a 4-column admin layout).
I think that's a good idea, but I also don't want to make too many assumptions here. If someone wants 10 columns of integer fields, they should be able to do it. But I don't want to limit the increment to 10s, because than would mess up someone doing a 4 column of 25%. Likewise, don't want to limit the increment to 5s because that would screw up the person trying to do 3 equal columns. Ultimately it doesn't seem like I can impose pre-defined increments here without excluding a lot of useful possibilities.
#33
Posted 21 February 2012 - 03:02 PM
- I think the slider collumn field isn't saving, because I have to reinstall first? haven't tried yet.
It doesn't save on repeater fields. It saves for normal fields.
@somartist | modules created | support me, flattr my work flattr.com
#34
Posted 21 February 2012 - 03:09 PM
The repeater is basically rendering the Inputfields for multiple pages, so chances are that the soft lock is hooked into something that is getting called several times rather than just once. We can take a closer look at interactions with other modules, though I'm thinking I should work out any bugs with the Repeater module first.
The soft lock checks for the user and only outputs error message when the user saved in the table isn't the same one. So what does that tell?
Browser cache is always a possibility too.
Could be but I got cache disabled and it occured multiple times... It seems gone one I removed range slider from repeater. Doesn't make sense, but maybe.
I don't understand. What's an RT? (retweet?)
I have a image field in the repeater and a RT (richttext) TinyMCE. If I upload an image it doesn't show up in the TinyMCE image dialog, but other images outside the repeater does.
Thumbnails work, but can't edit them anymore if it's in the repeater, the "edit" link opens in new window, there the url can't be found. It work with images outside repeater, even multiple.
@somartist | modules created | support me, flattr my work flattr.com
#36
Posted 21 February 2012 - 03:52 PM
I think that's a good idea, but I also don't want to make too many assumptions here. If someone wants 10 columns of integer fields, they should be able to do it. But I don't want to limit the increment to 10s, because than would mess up someone doing a 4 column of 25%. Likewise, don't want to limit the increment to 5s because that would screw up the person trying to do 3 equal columns. Ultimately it doesn't seem like I can impose pre-defined increments here without excluding a lot of useful possibilities.
That makes sense. That got me thinking, though (at the risk of overthinking
2/4 |========[]========| Columns: [ 4 ▼ ]
So if you're doing 10 columns of integer fields, you can easily jump to 1/10th, and if you're doing something like sixths, you don't have to stop to mentally calculate what percentage one of those is.
#37
Posted 21 February 2012 - 04:41 PM
I really think this will make the editors experience much more pleasant and easier. But it will at the same time ask for a more responsible and detailed work from the developer.
The columns are just great! I had to go look for the post where I asked this some time ago http://processwire.c...__fromsearch__1. Your implementation is way better
#38
Posted 21 February 2012 - 04:59 PM
Don't really see what it could be.
BTW it would be somehow be cool to update the #index when dragging an item. I think it could make sense since it isn't saved anyway. Though It may would be even cooler to have a title somehow "name" shown in the bar, that is recognized when collapsed not just #1,#2,#3.
@somartist | modules created | support me, flattr my work flattr.com
#39
Posted 21 February 2012 - 04:59 PM
So if you're doing 10 columns of integer fields, you can easily jump to 1/10th, and if you're doing something like sixths, you don't have to stop to mentally calculate what percentage one of those is.
assume that all colums are equal do you? screen shot show columns, lengths different
#40
Posted 21 February 2012 - 05:15 PM
That makes sense. That got me thinking, though (at the risk of overthinking
), how about a drop-down next to the slider that selects how many columns you want to divide into?
2/4 |========[]========| Columns: [ 4 ▼ ]
So if you're doing 10 columns of integer fields, you can easily jump to 1/10th, and if you're doing something like sixths, you don't have to stop to mentally calculate what percentage one of those is.
I think it's not as a good idea as it might sounds, you can't do smaller than 10% anyway..
so
- 10 elements easy
- 9 easy let it on 10%
- 8 set it to 10 or 12%
- 7 set it to 12%
- 6 set it to 15%
- 5 set it to 20%
- 4 => 25%
- 3 => 33%
- 2 => 50%
- 1 => let it how it is.
----
Label not translated. Bug?
Ryan. The label of the repeater field the one you can drag, doesn't show me the german label..
@somartist | modules created | support me, flattr my work flattr.com
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users













