How to add a keyboard shortcut for adding structured data

Hi all,

I need to add structure field data several dozens times a day. Therefore I’d like to add a keyboard shortcut to add this data to a single structured field I have. Could I somehow add this keyboard shortcut through a custom field clone of the structure field?

1 Like

Yea, you could basically just copy the structure field (panel/app/fields/structure) and either rename it or just modify it (it would then overwrite the default structure field. And basically add a kewydown event listener in assets/js/structure.js.

If it’s the only structure field, you could probably just call

$('.structure-add-button').click()

to trigger the add entry modal. At least, I think so.

Would be nice to have this in the core. If you have to add many entries to a structure field, it would really help to have a keyboard shortcut instead of trying to find the add button all over again. Think I’m gonna add this as a feature request on GitHub.

What happens if you have more than one structure field in the form?

It reminds me of a similar problem I had with my Splitview plugin. I could not use a shortcut key because the focus needed to be in the correct iframe.

In this case, for it to work you need to set focus to an element where the shortcut key should apply. To make it useful it needs to show what element is in focus. That means some kind of new design enhancements to select an element.

Maybe it’s too much work for too little benefit?

Ha ha, did not think of this :blush: So it would at least need an option again …

Well, if your solution above works, that would be enough.

I vote for having this in the core and be configurable in the blueprints. Then I can decide which structure field is mostly used and therefore get a keyboard shortcut or I assign different keyboard shortcuts to each.

But I’ll try @distantnative’s solution. Thanks for the help.

BTW Another suggestion: If I limited the number of characters for a page’s title in the blueprint, the add page modal dialogue should count characters too – not only the panel form. (PS I am remembering seeing something like this in a screen recording GIF from Bastian – am I wrong?)

Okay, I solved it like this:

  • 1st I copied the directory of the structure field from /panel/app/fields/structure to /site/fields/structure
  • then I’ve added two lines of code to /site/fields/structure/structure.php around line 126

$add->attr('data-shortcut', 'a'); $add->attr('title', 'a');

Et voilà.

PS I haven’t tested this “hack” extensively. So please handle with care.

1 Like

Okay one drawback: A potential title field gets auto-focussed. So when command-tabbing into the browser or control-tabbing to the tab with the panel form, the title field gets automatically focussed. So once I press any key its content gets replaced by that key. Therefore I still need to de-focus with the mouse and then enter my keyboard shortcut to add structure field contents. Little bummer.

Blueprint is an interesting solution. But what about if two fields have the same shortcut key? Then it just take the first, or the last one?

Yes, focus seems often to be a problem when using shortcut keys.