Sorry, we don't support your browser.  Install a modern browser

Allow custom fields with no front-end visualizaiton#237

I want to add IDs to a structure. Obviously, I don’t want the panel user to care or be aware of that, so I want this to be hidden. I could use the autoid, but it would be an overhead for my overly simple use case.

I have the following custom field:

use Kirby\Cms\App;
use Kirby\Toolkit\Str;

App::plugin('my/id-field', [
    'fields' => [
        'id' => [
            'props' => [
                'value' => function ($value = null) {
                    return $value;
                }
            ],
            'save' => function ($value) {
                return $value ?? Str::random(8);
            }
        ]
    ]
]);

In terms of back-end, it works exactly as intended - when the user saves their changes in the panel, the field is populated with a random string.

However, in the front-end, I have to either have some sort of visualization for the field, or I get the error “The field type “id” does not exist.”

Request: Allow field plugins to have some sort of way to opt-in for being hidden in the panel, similar to the hidden field type.

a month ago

Do you mean an option for the field configuration in the backend? Like this:

use Kirby\Cms\App;
use Kirby\Toolkit\Str;

App::plugin('my/id-field', [
    'fields' => [
        'id' => [
            'props' => [
                'value' => function ($value = null) {
                    return $value;
                }
            ],
            'save' => function ($value) {
                return $value ?? Str::random(8);
            },
            'hidden' => true
        ]
    ]
]);

I think this could work as a nice shortcut for such fields. I’m not sure how easy it would be to implement though. Until then, the best workaround is to define an empty field in your plugin JS to make the Panel happy. I understand that this is superfluous for the use-case, but as I said, it’s a workaround.

14 days ago

Even if I put an empty field, it still occupies space in the panel and looks weird. I need the field to be completely hidden.

The hidden option can be either in the front-end or back-end, I don’t think it matters.

What’s the current implementation for the hidden field shipped by Kirby? Is there a way you could use a similar approach?

12 days ago

You are right – the hidden field currently gets special treatment here: https://github.com/getkirby/kirby/blob/3.5.3/panel/src/components/Forms/Fieldset.vue#L6

So it’s currently not possible to implement hidden fields in plugins. In that context an option for the field to define the “hidden” status would make a lot of sense and would also simplify our own code.

11 days ago
1
Changed the status to
Planned
11 days ago
1