Select from existing or add new on-the-fly

Hi!
I’m new to Kirby! I’m not a proper developer, more of a designer that codes pretty well. Here’s my first post on the forum, and I’d love any help I can get.

So, I have a collection of artists. Each Artist have a structure field that holds multiple events (it’s a tour programme). Apart from the usual dates fields, every event has a venue. Venues can be same across different artists and consists of quite many fields. Now I’m looking for a way for the editors to reuse venues instead of typing the same information over and over again, while also being able to add new venues easily.

To my understanding I can setup a separate Venues page with each venue as a subpage, and then in the Artist blueprint use a page field that queries the Venues children. Another similar option is to use a structure field on the Venues page and use a select field with a query. The Venues page would never be visible in the frontend, it’s just in the panel to hold data.

Here’s the issue! None of these options give the editor the ability to add a new venue on the fly when filling out the event field on the Artist page.

I was happy to come across this plugin by @texnixe

The plugin seems to do more or less exactly what I needed. But unfortunately it seems it’s only for Kirby 2 :frowning:

Any smart approaches, plugins…? I feel I might be missing something obvious. It would be increadibly useful to be able to “quick add” to a collection without leaving the context where the data is actually used.

Tim

I’m not aware of a plugin for Kirby 3. I have always wanted to create a successor of this plugin for the pages field for the Kirby 3 port of the website for which I created it originally. But the sad truth is that I started but never finished.

As a workaround, you could add a location section to add new locations alongside the location field, so that users at least don’t have to leave the page. With the Custom Add Fields plugin it should even be possible to prevent a redirect to the new page: GitHub - steirico/kirby-plugin-custom-add-fields: Custom fields for Kirby's add dialog.

Yes! Thank you! I didn’t think about adding a pages section would show the add button… If you get around to update your selectplus plugin I’d love that, of course. But this solution works pretty well! Next I will improve it with the Add field plugin.

May I follow up with some additional questions in the same thread?

As the Venues (locations) are just data collections in the panel, and only output as event meta data through the Artist template:

  1. How to stop Venues from being accessible on the frontend?
  2. Page states – is it perhaps suitable to use only the Unlisted state for the venues?
  3. Could I create methods in the artist model to access the venue info etc? Can you help me with an example? Below is a simplificiation of what I’m doing now but I like to learn to work with controllers, models, collections instead… but my brain hurts.
  4. Filtering: How would I get a collection with all events from all artists, filtered by events that are not past, where the venue is in a particular city?
<?php
# templates/artist.php
# List all events for this artist

  foreach (
  $page
  ->events()
  ->toStructure()
  ->sortBy("startDate", "asc")
  as $event
  ):

  # Fetch event venue data from venue page 
  $venue = $event->venue()->toPage();
?>
  I can output things like this
  <?= $event->startDate() ?>, <?= $venue->city()?>, ...
  <?php endforeach; ?>

Either you add templates with a redirect to the error page or you add a route for the venues page and the children that does the same.

That makes sense to make sure they don’t show up when you filter by listed

Sure. Example code

<?php
class ArtistPage extends Page
{
  public function getVenueData($location)
  {
     $data = [];
     $venuePage= page('venues')->find($location); // where location is the id to the location as stored in the event page
      // then return the data as need
      if ($venuePage) {
        return [
          'city' => $venuePage->city()->value(),
           // etc.
         ];
      }
  }
}

Since the event seem to be stored in a structure field for each artist, you would have to create a new collection of all venues first, then filter by date and location.