Sorting custom user field dropdown items

AI-generated summary

jenmck seeks a more efficient way to manage a custom user field dropdown containing a long, required list of options. Currently, new items are appended to the bottom, forcing manual re-alphabetization via up-arrow clicks for each addition. The user notes that an AI-suggested path (Admin > Customize > User Fields) does not exist and no relevant API endpoint was found in the documentation.

While acknowledging a related topic on updating field values via cron jobs, jenmck expresses hesitation about this approach. Key questions raised include: whether there is a simpler sorting method than manual clicking; if a “display alphabetically” option or theme component is feasible; whether existing user selections persist if the list is replaced via script as long as values match; and the likelihood of an API endpoint being added to support this functionality.

I have a custom user field with a very long list of dropdown options. For reasons, users are not allowed to enter their own value in this field, and this field must exist as a dropdown, and it is a required field for all users.

From time to time, I need to add or remove items to the list. Because it’s such a long list, I have it alphabetized.

The pain here is that new items are added to the bottom, and i need to manually click the up arrow for each new item in order to re-alphabetize the list.

I did a search, and got this AI result, which is incorrect - there is no Admin > Customize > User Fields page.

I checked for an API endpoint at docs.discourse.org and didn’t see anything related to custom user fields.

This topic: Dynamically update available user field values during a profile fill in does outline a method for updating the list using a cron job (though it’s not quite my use case, it is similar enough). I’m very leery of doing it this way, though.

I have searched for other topics related to this; I know I had asked about it about 3 years ago, but didn’t want to necro that topic.

My questions:

  • is there an easier way to sort dropdown lists than clicking the arrow manually for each item
  • would it seem like something feasible to add a display alphabetically option or have it manually display alphabetically using a theme component, or is this more complicated to accomplish than it seems?
  • if the only option is to go the route of creating a cron job for it, if the dropdown list is completely replaced, would current users retain the selection they’ve already made, if it is listed exactly the same in the replaced list?
  • what would be the chances that this could be added as an API endpoint?

Sincerely,
someone with a lot of clicking to do