Update example

This commit is contained in:
Josh Johnson 2017-12-08 15:14:38 +00:00
parent 053ec770d3
commit e9469816d5

View file

@ -259,24 +259,24 @@
<option value="Vue">Vue</option>
</select>
<p>Below is an example of how you could have two select inputs depend on eachother. 'Boroughs' will only be enabled if
the value of 'States' is 'New York'</p>
<label for="states">States</label>
<select class="form-control" name="states" id="states" placeholder="Choose a state">
<option value="Michigan">Michigan</option>
<option value="Texas">Texas</option>
<option value="Chicago">Chicago</option>
<option value="New York">New York</option>
<option value="Washington">Washington</option>
<p>Below is an example of how you could have two select inputs depend on eachother. 'Tube stations' will only be enabled if
the value of 'Cities' is 'London'</p>
<label for="cities">Cities</label>
<select class="form-control" name="cities" id="cities" placeholder="Choose a city">
<option value="Leeds">Leeds</option>
<option value="Manchester">Manchester</option>
<option value="London">London</option>
<option value="Sheffield">Sheffield</option>
<option value="Newcastle">Newcastle</option>
</select>
<label for="boroughs">Boroughs</label>
<select class="form-control" name="boroughs" id="boroughs" placeholder="Choose a borough">
<option value="The Bronx">The Bronx</option>
<option value="Brooklyn">Brooklyn</option>
<option value="Manhattan">Manhattan</option>
<option value="Queens">Queens</option>
<option value="Staten Island">Staten Island</option>
<label for="tube-stations">Tube stations</label>
<select class="form-control" name="tube-stations" id="tube-stations" placeholder="Choose a tube station">
<option value="Moorgate">Moorgate</option>
<option value="St Pauls">St Pauls</option>
<option value="Old Street">Old Street</option>
<option value="Liverpool Street">Liverpool Street</option>
<option value="Kings Cross St. Pancras">Kings Cross St. Pancras</option>
</select>
</div>
</div>
@ -475,13 +475,14 @@
shouldSort: false,
});
var states = new Choices(document.getElementById('states'));
var cities = new Choices(document.getElementById('cities'));
var tubeStations = new Choices(document.getElementById('tube-stations')).disable();
states.passedElement.element.addEventListener('change', function(e) {
if (e.detail.value === 'New York') {
boroughs.enable();
cities.passedElement.element.addEventListener('change', function(e) {
if (e.detail.value === 'London') {
tubeStations.enable();
} else {
boroughs.disable();
tubeStations.disable();
}
});
@ -523,7 +524,6 @@
}
});
var boroughs = new Choices(document.getElementById('boroughs')).disable();
});
</script>