Using toggle field in page create dialog

  1. Trying to use a toggle field in a page create dialog I get Field type "toggle" not supported in create dialog. Consulting the docs, the toggle field is indeed not listed in the supported field types. It seems like a basic field so I was a bit surprised and want to make sure this is correct or I’m missing something obvious?

  2. Checkboxes on the other hand does work in the create dialog. But I bumped into another thing that prevents me to use a checkbox. I must use a when condition, and the checkboxes field doesn’t support that, it seems?

  3. So back to the toggle field: is there any clever workaround to make a toggle field work in the create dialog? If there’s not any reason for it to not be supported, if it’s just an oversight perhaps I could make a field plugin that extends the toggle…? I wanted to give it a try but got stuck on a detal. Docs says this:

Custom field types are disabled by default. To enable them, add your field type name to:
Kirby\Panel\PageCreateDialog::$fieldTypes[] = 'yourFieldType'

But I don’t understand where I should add that code?


Here’s the relevant part of the blueprint (it’s quite a big blueprint so I removed everything I believed was unrelated)

title: Event
num: zero

create:
  title: "{< page.venue.toVenue.title >} • {{ page.startDate.toDate('EEE yyyy-MM-dd') }}"
  slug: "{{ page.startDate.toDate('yyyy-MM-dd') }}-{{ page.venue.toVenue.city.slug }}-{{ page.venue.toVenue.title.slug }}-{{ page.startTime.toDate('Hmm') }}"
  status: listed
  redirect: false
  fields:
    - startTime
    - endTime
    - timeTBD

columns:
  dateCol:
    width: 7/12
    sections:
      eventDates:
        type: fields
        fields:
  
          timeTBD:
            label: Announce time later?
            type: toggle
            width: 3/12
            text:
              - "no"
              - "yes"
          
         timeTBDInfo:
            type: info
            label: "Door time, start time and endtime"
            width: 9/12
            theme: warning
            text: Time is set to be announced later (TBA)
            when:
              timeTBD: true
              
          doorTime:
            label: Door open time
            type: time
            width: 3/12
            when:
              timeTBD: false

          startTime:
            label: Start time
            type: time
            step: 15
            width: 3/12
            required: true
            when:
              timeTBD: false
          
          endTime:
            label: End time
            type: time
            time: true
            step: 15
            width: 3/12
            when:
              timeTBD: false
          

Could you post what you tried?

This would go into a plugin’s index.php

I do think it’s an oversight that toggle isn’t in the default list of supported fields. As far as I know, we only tried to exclude fields that need to open themselves dialogs as Kirby doesn’t support nested/stacked dialogs currently.

Hi,
To investigate I just tried with a custom toggle that just adds itself to the allowed list:

// toggleExtended/index.js
panel.plugin("tamburlane/toggleExtended", {
    fields: {
        toggleX: {
            extends: "k-toggle-field"
        }
    }
});
<?php
// toggleExtended/index.php
Kirby\Panel\PageCreateDialog::$fieldTypes[] = 'toggleX';
Kirby::plugin('tamburlane/toggleExtended', [
  'fields' => [
    'toggleX' => [
      'extends' => 'toggle',
      'props' => [
      ]
    ]
  ]
]);

Result:

Test 1: When toggle has no default set (or default: false):
Initially the when conditions does not trigger for any fields that has a condition for the toggle. They are not visible at all. But, if I toggle it to true and back to false again, it triggers the conditions so the correct fields are revealed.

Test 2: When toggle is set to default: true
All conditions are working as expected!

So any toggle that is initially off fails to trigger when-conditions until toggled once…

Oh yes regarding the checkboxes, I found this thread so I assume it is confirmed it is not expected to work anywhere to use when with checkboxes. It doesn’t seem to be about the page create dialog:

The toggle on the other hand …