Skip to content

Commit

Permalink
Change custom form snippet
Browse files Browse the repository at this point in the history
  • Loading branch information
blagojabozinovski committed Sep 6, 2024
1 parent 27035f4 commit 5f063a4
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions ckanext/scheming/templates/scheming/form_snippets/custom.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{% import 'macros/form.html' as form %}


{{ form.select('country', label=_('Country'), options=[{'name':'France', 'value': 'France'},{'name': 'Austria', 'value': 'Austria'}], selected='Austria', error='') }}
{{ form.select('city', label=_('City'), options='', error='') }}
<!-- <form>
<label for="country">Select Country:</label>
<select id="country">
<option value="">Select a country</option>
<option value="France">France</option>
<option value="Austria">Austria</option>
</select>
<label for="city">Select City:</label>
<select id="city">
<option value="">Select a city</option>
</select>
</form> -->


<script>
document.addEventListener('DOMContentLoaded', function() {
const cityOptions = {
France: ['Paris', 'Lyon', 'Marseille', 'Nice'],
Austria: ['Vienna', 'Salzburg', 'Graz', 'Innsbruck']
};

const countrySelect = document.getElementById('country');
const citySelect = document.getElementById('city');

countrySelect.addEventListener('change', function() {
const selectedCountry = countrySelect.value;
const cities = cityOptions[selectedCountry] || [];
citySelect.innerHTML = '<option value="">Select a city</option>'; // Reset the city dropdown

cities.forEach(function(city) {
const option = document.createElement('option');
option.value = city;
option.textContent = city;
citySelect.appendChild(option);
});
});
});
</script>




0 comments on commit 5f063a4

Please sign in to comment.