Formmenu Sorting

Hi, is there any way to sort the data within "Formmenu"? This is a simple example, but the purpose is for the ones with larger data or when updated with new items

From {formmenu: name=Example; default=A;D;B;C;A}

To {formmenu: name=Example; default=A;A;B;C:D}

Thank you!!!

1 Like

Hi Martin! You can do this using a published Google Sheet in .csv format. You would add your data to the spreadsheet and then sort it there. I hope that helps.

Take a look at this thread.

This may be more complex than it's worth, but you can use the values setting to provide a list of options to a formmenu. You can use a formula to sort that list.

For example:

{formmenu: name=Example; values={=sort(["A", "D", "B", "C", "A"], (a, b) -> comparestrings(a, b))}}

@martinhgps - on top of what Scott said, you can create a list and then use it inside the formmenu command:

{list=["A", "D", "B", "C", "A"]}
{sortedlist=sort(list, (a, b) -> comparestrings(a, b))}
{formmenu: name=Example; values={=sortedlist}}

This is practically the same thing that Scott did, but broken up into individual steps for ease of understanding.

And here's one more bit that's not really related to your question, but that I know will tickle your imagination.

Lists can contain variables. This means you could add a formtext with a label, then use that label inside the list for your formmenu values to insert ad-hoc menu items for that insertion.

{formtext: name=text; default=some text}
{list=["A", "D", "B", "C", "A", text]}
{sortedlist=sort(list, (a, b) -> comparestrings(a, b))}
{formmenu: name=Example; values={=sortedlist}}

Try changing the content of the formtext field and note how it affects the dropdown menu items.

1 Like