Programmatically change the content of the file field

How to listen to events of changing the value of fields using Kirby? Can you enlist your help and get links to the CMS Kirby documentation section to implement each of the steps you have proposed?

  • Your code has to listen to a change in that field even before that change is stored anywhere on the server
  • When a change happens, your code has to get the value from that field (from the content store) and query the files and tags via a route/endpoint.
  • Then insert the results on the fly into the other fields.
    I would be very grateful!

You have to look into the custom field documentation:

Both your tags field and the files field need a listener.

Then you can get the value from the content store: https://getkirby.com/docs/reference/plugins/internals/store-content

Custom API endpoints: https://getkirby.com/docs/reference/plugins/extensions/api#custom-endpoints

1 Like

Thank you very much for the information. They will study and implement their plans.

I wonder if it would make sense to create a custom set of fields for this purpose rather than individual fields that do the same thing.

I haven’t seen Pages Field in the UI Kits.
Otherwise, how can I work with the field and hang an event listener on it?

Looks like it is missing, don’t know why.

Since he is not there, then there is no way to interact with him? And accordingly, I can’t hang an event listener on it so that the second field understands the page has changed or not?

It doesn’t mean any such thing. The UI Kit is intended for you to use in your own Panel extensions. Has nothing to do with you being able to work with that field from your code.

Plus the fact that it is not documented for whatever reason, doesn’t mean you can’t use this field type.

If you want to address a particular field, you have to get it by it’s name, not type anyway.

Tell me, what am I doing wrong? I did everything according to the instructions. But when I try to select a page in a custom floor, the panel gives an error: Cannot read property ‘field’ of undefined


Did it compile without errors?

And please don’t post code in screenshots, we cannot test it then. You can copy and paste it here. Thank you.

Yes, everything compiled without errors.

<?php

Kirby::plugin('denis/custom', [

    'fields' => [

        'custom' => [

            'extends' => 'pages',

            'props' => [

            ]

        ]

    ]

]);

import CustomField from "./components/CustomField.vue";

panel.plugin("denis/custom", {

  fields: {

    custom: CustomField

  }

});

<template>

  <k-pages-field v-model="pages" name="pages" label="Pages" />

</template>

Sorry, but is there any information about the error when selecting the page?

Have you checked the browser console?

In fact, the field should at least appear in the page with your code, but then all the rest will not work because the logic is missing.

A field appears. But after pressing the select button, it gives an error. I wrote about this yesterday. What kind of logic are you talking about?

If you look at the original field, it imports the filepicker mixin and does all sorts of other stuff. It won’t just work by putting a simple template into the CustomField.vue file.

But I’ve never extended a field myself yet, so can’t really tell you much about it. Looking at example fields in existing plugins can probably help.

You can find some fields here: https://getkirby.com/plugins?category=panel

You can find the original field vue files here: https://github.com/getkirby/kirby/tree/master/panel/src/components/Forms/Field

Thank you again. You are constantly helping out. I will sort this out.

Sorry I can’t help you more with this… We definitely need more docs.

And can I just expand the field. Around the same way I can do this in a .js file?

panel.plugin("your/plugin", {
  fields: {
    hello: {
      extends: "k-text-field"
    }
  }
});

Or I can ask the question for https://forum.getkirby.com/u/bastianallgeier/summary ?

@distantnative, @bastianallgeier Can you provide any insights, please?

We are definitely lacking docs for custom field implementations. I’m really sorry about that. Please give me some time to setup an example for this today and get back to you.

1 Like