Support

Account

Home Forums Add-ons Repeater Field Pre-polulated repeater field?

Solving

Pre-polulated repeater field?

  • Hi,

    I would like users to add rows into a repeater field which subfields come from a given list. Is there a way to get the values of the repeater field pre-populated when adding a new row?

    Let’s say I have a list of items on a restaurant menu. Each item has a name and a price. Then I have a post for a customer with a repeater field called “bill”. My client would like to add items for the menu into this repeater field without having to copy them manually.

    – I have tried the relational field, linking menu items and customer’s bills, but that won’t allow me to change prices in the future or add the same item several times. 🙁

    – A repeater field with a drop-down as subfield doesn’t allow me to get both the name and the price (i.e. soup, 5$) 🙁

    Any ideas?

  • This example I have shows how to dynamically populate several additional fields base on a relationship field https://github.com/Hube2/acf-dynamic-ajax-select-example/tree/master/dynamic-fields-on-relationship.

    If you look at some of my other examples you might be able to work out what changes need to be made for a repeater, but basically you can get the row your on by using something like $(e.$el).closest('.acf-row');

  • Hi John, thanks for your help. I have tried to implement your code, but it’s a bit difficult for me to understand it.

    I have tried another approach though. Using the code on this link I have managed to store both the name and the price as a Json. Then all I have to do is decoding that and extract the elements of the array.

    It may not be the best way of doing it, but it seems to work.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.