-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use location component partials for country/state selects
- Loading branch information
Showing
3 changed files
with
46 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{% set countryId = countryId|default(post('country_id')) %} | ||
{% set uniqueId = post('country_unique_id', uniqueId|default('stateControlSelector')) %} | ||
{% set countries = __SELF__.availableCountries|default([]) %} | ||
|
||
<select | ||
name="country_id" | ||
class="form-select" | ||
data-request="onAjax" | ||
data-request-data="{ | ||
country_unique_id: '{{ uniqueId }}' | ||
}" | ||
data-request-update="{ | ||
'@form-select-state': '#{{ uniqueId }}' | ||
}"> | ||
{% for country in countries %} | ||
<option value="{{ country.id }}" {{ country.id == countryId ? 'selected'}}>{{ country.name }}</option> | ||
{% endfor %} | ||
</select> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{% set countryId = post('country_id', countryId|default(null)) %} | ||
{% set stateId = post('state_id', stateId|default(null)) %} | ||
{% set uniqueId = post('country_unique_id', uniqueId|default('stateControlSelector')) %} | ||
{% set countries = __SELF__.availableCountries|default([]) %} | ||
{% set country = countries.find(countryId)|default(countries.first()) %} | ||
{% set states = country.fetchStates() %} | ||
{% set optionsOnly = post('country_unique_id') %} | ||
|
||
{% if optionsOnly %} | ||
<option></option> | ||
{% for state in states %} | ||
<option value="{{ state.id }}" {{ state.id == stateId ? 'selected'}}>{{ state.name }}</option> | ||
{% endfor %} | ||
{% else %} | ||
<select | ||
id="{{ uniqueId }}" | ||
name="state_id" | ||
class="form-select" | ||
> | ||
<option></option> | ||
{% for state in states %} | ||
<option value="{{ state.id }}" {{ state.id == stateId ? 'selected'}}>{{ state.name }}</option> | ||
{% endfor %} | ||
</select> | ||
{% endif %} |