Add structure entry from another field

Hey folks,

at the moment I’m working on a tool for a client and need to add a structure entry from another field. Ideally, it just works like the normal “add entry” function, but without the modal.

For background: in the structure field I store information about other pages (URI and maybe custom title from within the structure field). Above the field I have a custom search field to filter through the pages which can be stored in the structure field. When I get the results, I just want to give the user the ability to click on a button next to the result and the page get’s added as an entry (and also to add all at once, but that’s another topic). Afterwards, the entry should be editable of course, like the usual ones. Oh, and I am using the Builder plugin, but this relies on the structure field, so I think this would not make much difference…

Can someone point me to the right direction with this? It is my first real custom field, so I am a bit unexperienced with this kind of stuff :wink:

Thanks guys,

Jakob

What information do you store inside the structure field for each item? Only the URI of the page that has been selected from the search or also other information?

Yes, basically only the URI (and fieldset, because I am using the builder plugin). Everything else (custom title, custom text, one or two options) can be added later on when editing an entry, those information are not part of the search.

OK. I was asking because I was thinking about using a simpler field than structure for this, but if you want to add additional data to each entry, structure makes sense.

Maybe you can find a solution to add items via JavaScript in the source of the structure field. Probably it makes sense to copy the field to your own field and add another route that takes the page URI and then adds a new entry from the backend. That would be least hacky.

1 Like

Okay, I got it working. Now I need some “field reloading” – the search should stay (with query and showing results), the other, “content” field should be reloaded so that the changes are visible instantly. Do you have an idea how to solve this? I played around with app.content.reload(), but of course this reloads the whole page…

The Panel uses server-side templates to keep it simple and increase performance, so you can’t easily reload only parts of the UI. Reloading completely will make sure that everything is consistent regarding state.

Okay, I see. Thanks for clarifying – I will search for another approach then, where the “gone” search wouldn’t be a big deal. Now it is, because the user might want to add multiple items to the structure entry, and currently he has to search-and-click five times for the same thing. Maybe I’ll add checkboxes and just one add button…