|
31 | 31 | <label for="state">State</label> |
32 | 32 | <div> |
33 | 33 | <select autocomplete="off" name="state" data-country-selector="state-selector" required> |
34 | | - |
35 | | - <?php foreach ($state_list as $state) : ?> |
36 | | - <option value="<?= $state['code'] ?>" <?php if ($state['code'] == $state_code) { |
37 | | - echo 'selected'; |
38 | | - } ?>> |
| 34 | + <?php foreach ($state_list as $state): ?> |
| 35 | + <option value="<?= $state['code'] ?>"> |
39 | 36 | <?= $state['name']; ?> |
40 | 37 | </option> |
41 | 38 | <?php endforeach; ?> |
|
45 | 42 | <div class="info-container country"> |
46 | 43 | <label for="country">Country</label> |
47 | 44 | <select autocomplete="off" name="country" data-country-selector="selector" required> |
48 | | - <?php foreach ($country_list as $country) : ?> |
49 | | - <?php |
50 | | - $current_code = $country["code"]; |
51 | | - $selected_country = false; |
52 | | - if (isset($country_code) && !is_null($country_code)) { |
53 | | - if ($current_code == $country_code) { |
54 | | - $selected_country = true; |
55 | | - } |
56 | | - } else { |
57 | | - if ($current_code == 'US') { |
58 | | - $selected_country = true; |
59 | | - } |
60 | | - } |
61 | | - ?> |
62 | | - <option value="<?= $country["code"] ?>" <?= $selected_country ? 'selected' : '' ?>> |
| 45 | + <?php foreach ($country_list as $country): ?> |
| 46 | + <option value="<?= $country["code"] ?>"> |
63 | 47 | <?= $country["name"]; ?> |
64 | 48 | </option> |
65 | 49 | <?php endforeach; ?> |
|
83 | 67 | <script> |
84 | 68 | (() => { |
85 | 69 | const countryList = <?= $country_list_json_blob ?>; |
| 70 | + const initialCountry = "<?= $country_code ?>"; |
| 71 | + const initialState = "<?= $state_code ?>"; |
86 | 72 | if (document.readyState === "loading") { |
87 | 73 | document.addEventListener("DOMContentLoaded", () => { |
88 | 74 | const countrySelectorEl = document.querySelector("[data-country-selector=selector]"); |
89 | 75 | const divisionSelectorEl = document.querySelector("[data-country-selector=state-selector]"); |
90 | 76 |
|
91 | | - new CountrySelector(countrySelectorEl, divisionSelectorEl, countryList); |
| 77 | + new CountrySelector(countrySelectorEl, divisionSelectorEl, countryList, initialCountry, initialState); |
92 | 78 | }); |
93 | 79 | } else { |
94 | 80 | const countrySelectorEl = document.querySelector("[data-country-selector=selector]"); |
95 | 81 | const divisionSelectorEl = document.querySelector("[data-country-selector=state-selector]"); |
96 | | - |
97 | | - new CountrySelector(countrySelectorEl, divisionSelectorEl, countryList); |
| 82 | + new CountrySelector(countrySelectorEl, divisionSelectorEl, countryList, initialCountry, initialState); |
98 | 83 | } |
99 | 84 | })(); |
100 | 85 | </script> |
|
0 commit comments