Jump to content

Something like... repeater field with only one entry allowed


benjaminE
 Share

Recommended Posts

Hello,

Is there a way to group together fields, like in a repeater field, but only allow there to be one set per template?

I looked into the fieldtab field but this doesn't allow for certain features that a repeater would - ie, allow the same field to be used at least twice within a page (eg, outside a repeater and within a repeater), and to add a group of fields into a template as one chunk.

This would seem like a handy feature feature and I'm probably missing something!

Many thanks in advance,

ben

Link to comment
Share on other sites

To re-use the same field multiple times in one template you are talking about repeaters.

Otherwise if you just want to group fields together neatly in a template you might want to try a fieldset - but this is simply a wrapper for grouping fields together, it won't let you save fields as a group and re-add the whole group to another template (I can't imagine any scneario where you would actually want to re-use the same fields enough times to warrant this type of functionality).

Link to comment
Share on other sites

I think the idea is that you could have a say a "customer" template and assign "phone, address, etc" fields to them, then you could make a shipping group and use the same fields again so the the references are simple clean and consistent.

Example

$customers = $pages->find("template=customers");

foreach($customers as $customer){
   
   // customer personal info
   echo $customer->phone;
   echo $customer->address;

   // customer shipping info
   echo $customer->shipping->phone;
   echo $customer->shipping->address;

}

I believe Ryan is working on something called ProFields that will allow this, though I believe it will be a payed module (with much more that just this functionality). It'd be conceivable that modifying the repeater for this basic functionality wouldn't be too difficult, though I imagine what Ryan is making will come with an abundance of reason to forgo the effort and just purchase what he creates.

  • Like 1
Link to comment
Share on other sites

Ah, right. In that case you can only copy the fields one at a time (from the advanced tab). But again though, I'm not sure where this would save a lot of time as such fields are set up once and that's it.

It would be interesting to hear benjaminE's use case.

Link to comment
Share on other sites

Thanks for all your responses and apologies for not being super clear. An example would be useful, agreed. So here goes...

Let's say I want to create a group of fields which would compromise an article - headline, body, image - and I want to be able to insert this article "chunk" into any given template. A repeater would do the job here, except in this instance I don't want the user to be able to add more than one article (which is what a repeater does best).

A repeater is so close to doing exactly what I want, I just wondered whether there was a way to limit the iterations to 1 (like you can with an image field). This would basically solve the problem. I believe adamsprujit has understood what I want and what Ryan is building does sound good, but repeaters are already so close!

Pete: the reasons I want to do this with a repeater-like field rather than simply adding the fields one-by-one to templates are:

(1) As adamsprujit says: it makes outputting in the template neat,

(2) It makes adding the fields to the template quicker, and,

(3) It means you don't have to create lots of fields... Say you already have a headline field - essentially a basic text field - and you're already using it in a template, you can re-use it in the same template if it's in a repeater. You don't have to go and make another field - eg, article_headline - to use for the article.

I hope that clarifies things. Any thoughts?!

  • Like 1
Link to comment
Share on other sites

Nope - you've still lost me on why you would want to re-use fields that make up an article (which is a single thing) within the same template. It doesn't make sense to me.

Many (infinite, within reason) separate pages can use the same template, each article would surely be a separate page using that same template? I still don't see the reason to re-use those fields within the same template.

  • Like 1
Link to comment
Share on other sites

Nope - you've still lost me on why you would want to re-use fields that make up an article (which is a single thing) within the same template. It doesn't make sense to me.

Yeah, have to agree with Pete here, I think your example makes less sense then mine ???, maybe it's just the way you've explained it, but what I'm picturing seems more complex than necessary.

Link to comment
Share on other sites

I think benjaminE is saying a repeater with a limit on the number of items it can contain would work. In that case, what most people do (i'm not a fan), is allow for multiple repeater entries, however only display the first repeater item in your template. 

I agree, it would be nice to use a field group that would group fields together like a repeater, but w/o the option to add multiple items. If it worked the same way as repeaters, you could use the field in a field group and outside of a field group, but it's easy enough to create a new field.

Link to comment
Share on other sites

I like the idea of this. Though my need is less the part of reusing existing fields, but creating a fieldgroup bundled with its fields. For sure it would a nice if I could even reuse existing fields like "title" and access them like somehow like this "$page->myfieldgroup->title", but I never missed this feature.

I try to explain my usecase:

I have some templates with a fieldgroup "metainfo" with the fields "browsertitle" and "meta_description". Currently I have to assign all these fields one by one to my templates. And if I later need some additional meta infos for facebook like "og_image" and "og_title" I have to edit all my templates to add these fields. If we would have some kind of defined fieldset, I could just assign my new fields to this fieldset and all my templates would have the new fields.

  • Like 2
Link to comment
Share on other sites

  • 2 years later...

Are there any updates on this topic? Is there a plan to develop such a field type? I would really appreciate if such a type would be implemented.

My use case is the following:

I have a group of fields that serve as a config for each of my templates. So i have 3 fields that are the same in every template. Currently there are two possibilities to add those fields to each template: adding the single fields to each template, or creating a repeater field and add the fields there. I am currently using the second approach which is working, but its not perfect since i only need one config per template. 

So i would need just a grouping field where i can add/remove/edit fields inside, which are changed then inside all templates, but without using a repeater (since i only need those fields once in each template)

hoping my usecase is clear and someone it motivated to make this possible.

In my opinion this would be a really awesome feature and would help a lot of people.

Thanks in advance :)

Chris

Link to comment
Share on other sites

I've a basic mockup of such a feature/fieldtype sitting here, but I've currently not the time to look further into it. It should be a "single page field" with features of both pagetables and repeaters (auto-generation / deletion, auto-naming, real template as base for pages).

Link to comment
Share on other sites

  • 3 weeks later...
  • 4 months later...

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

×
×
  • Create New...