Last active
September 18, 2015 14:49
-
-
Save dtothefp/4dfdc827d7c46f70cb6d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var $select = $('#id_donate_state'); | |
var lastSelectVal = null; | |
$select.on('change', function(e) { | |
var val = e.target.value; | |
var isUnSelected = val === '' || _.isUndefined(val) || _.isNull(val); | |
if (isUnSelected) { | |
this.value = lastSelectedVal; | |
} else { | |
lastSelectedVal = val; | |
} | |
}); | |
let selects = document.querySelector('.form-content').querySelectorAll('select'); | |
selects = [...selects]; | |
selects.forEach((select) => { | |
select.addEventListener('change', (e) => { | |
const val = e.target.value; | |
const isUnSelected = val === '' || _.isUndefined(val) || _.isNull(val); | |
if (isUnSelected) { | |
select.value = lastSelectedVal; | |
} else { | |
lastSelectedVal = val; | |
} | |
}, false); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment