Merge pull request #2248 from betagouv/fix_2247_multiple_linked_list

[fix #2247] linked drop down list: fix js scope pb
This commit is contained in:
LeSim 2018-07-13 13:33:05 +02:00 committed by GitHub
commit 850be59648
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,14 +1,14 @@
document.addEventListener('turbolinks:load', function() {
var primaries, i, primary, secondary, secondaryOptions;
var primaries, i;
primaries = document.querySelectorAll('select[data-secondary-options]');
for (i = 0; i < primaries.length; i++) {
primary = primaries[i];
secondary = document.querySelector('select[data-secondary-id="' + primary.dataset.primaryId + '"]');
secondaryOptions = JSON.parse(primary.dataset.secondaryOptions);
primaries[i].addEventListener('change', function(e) {
var option, options, element, primary, secondary, secondaryOptions;
primary.addEventListener('change', function(e) {
var option, options, element;
primary = e.target;
secondary = document.querySelector('select[data-secondary-id="' + primary.dataset.primaryId + '"]');
secondaryOptions = JSON.parse(primary.dataset.secondaryOptions);
while ((option = secondary.firstChild)) {
secondary.removeChild(option);