States not shown in alphabetical order

Created on 9 February 2023, over 1 year ago
Updated 21 November 2023, 7 months ago

1.0 Problem/Motivation

State (and probably county) fields aren't listed in alphabetical order in select fields.

2.0 Detailed steps to reproduce (embed screenshots)

Create a webform that has a country, state and county field. Examples of countries with states/provinces out of order include United States, United Kingdom, India, and Bermuda.

This is because JSON object elements aren't ordered, so they're reordered by their key, which is the primary key in `civicrm_state_province`. It's not immediately obvious that they're not alphabetical because many states/provinces are alphabetical in that table, but not everywhere.

3.0 Proposed resolution

The data is returned correctly from the stateProvince and county callbacks, but the browser re-sorts the JSON by id. I'm guessing before PR 813 it sorted by abbreviation, which was more acceptable.

We need to modify fillOptions to convert the object to an array and sort them (e.g. myVar = Object.entries(data).sort(([,a],[,b]) => a > b). Then we need to modify the rest of the function to handle the data coming from an array rather than an object.

We'll try to make some time for this if no one else gets to it first, but it's not a priority for us.

πŸ› Bug report
Status

Active

Version

6.0

Component

Webform/Drupal

Created by

πŸ‡ΊπŸ‡ΈUnited States MegaphoneJon

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024