Fill a field automatically with other field's value

Hi!
I have a multiselect field of ā€˜artistsā€™ which lets the user pick 5 artist pages:

artists:
        label: Pick 5 artists
        type: multiselect
        options: 
          type: query
          query: site.page('artists').children.template("artist")

In addition to that I have a second field of ā€˜5 book picksā€™ that lets the user pick 5 book pages:

recommendations:
        label: Pick 5 book recommendations
        type: multiselect
        max: 5
        options: 
          type: query
          query: site.page('books').children.template("book")

each book from the picks has an artist field with artist page as a value. I wish to collect all the artist pages from the ā€˜5 book picksā€™ and make it as the value of the first field (multiselect field of ā€˜artistsā€™).
On top of it, if possible, I wish that this automatically filled field (ā€˜artistsā€™) will be invisible in the panel.

In template I managed (thanks to the forum) to get the artist value of each book:

$recommended_books = $page->recommendations()->toPages(',');
$pick_artists = $recommended_books->pluck('artist', ',', true);

But how can I use it in the panel?

Thanks a lot! :pray:

Why do you want to have the artists field in the panel if you donā€™t want people to see or edit it?

Well, all pages have artist field. But this specific page doesnā€™t have one artist but 5, these are the artists of the the 5 book picks.

at the end of every page I show related pages according to artist field so I need this page to have artist field as well.

Right now it works good - the user pick 5 artists and 5 books separately. But I donā€™t want this double multi-selection. If only the artists from the books would be filled automatically in the artist field then I could save the user from filling it twice. Also the lists of artists and pages are big and might be confusing and I donā€™t want them to fill wrong artists.

I hope Iā€™m understood :pray:

Iā€™d still recommend to remove the ā€œpick 5 artistsā€ field from the blueprint.
I mean you already seem to have a separate blueprint for that kind of page.

Iā€™d move the problem to the template, or to a model, or to a controller. Specifically to where you generate the ā€œrelated pagesā€; because you anyway need special logic to generate those if you suddenly have 5 artists instead of only 1.

1 Like