Position buttons + function for creating repetitive components

I wasn't sure if this should be in the Question's section or the Feature Ideas section.

I'm trying to optimize / prettify my snippet (link to bundle).

I would like to see if there is anyway to have the buttons ("add", "select all", "unselect all") be positioned / aligned to the far right of the screen without affecting anything else on the same line.

Also, those three buttons use the same code / scripting over and over again with just really changing a few variables (the formtext and and formmenu list that needs to be modified). Is there any way to put that code in a separate snippet that I can import and just pass required variables into it to cut down on repeating myself (That or make a custom function that allows for the same idea)

Thanks again

Hi @Doc_Krieger

Sure, you can use the {repeat} and the {import} commands to optimize it as follows:

{note: trim=right}Hx sections: {formmenu: tx tried; red flags; name=hx_selected; cols=10; multiple=yes}{endnote}
{repeat: for label in hx_selected}
{import: /entry}
{endrepeat}

{=label}: {if: count(selected) = 0}none{endif}{formmenu: values={=list}; name=selected; multiple=yes}{note} {formtext: name=add}{button: if add = ""
notify(label & " cannot be blank")
return
endif
selected = merge(selected, [add])
add = ""
; label=add}{button: selected = [ ]; label=unselect all}{button: selected = list
; label=select all}{endnote}

Regarding the buttons to be positioned on the far right of the screen, one workaround can be inserting a table with two columns, adding the buttons to the second column, and adjusting the width of the first column to fit the popup window, then adding your inputs to it. However, this is not a stable solution, as the screen or inputs size may vary, and the table itself may also affect the final layout and content of your snippet. Unfortunately, there's no other way to do that currently.

Let me know if you need any more help.