Skip to content

Instantly share code, notes, and snippets.

@guillaumepiot
Created January 29, 2018 17:09
Show Gist options
  • Save guillaumepiot/e1a1a7d7075625f9d9c0683f96a7502e to your computer and use it in GitHub Desktop.
Save guillaumepiot/e1a1a7d7075625f9d9c0683f96a7502e to your computer and use it in GitHub Desktop.
Show / hide fields based on field value
var required_financial_fields = {{LOAN_REQUIRED_FINANCIAL_FIELDS|safe}};
var fields = []
for(var key in required_financial_fields) {
fields = fields.concat(required_financial_fields[key])
}
function hideAllFields() {
for(var i = 0; i < fields.length; i++) {
document.querySelector('[name='+fields[i]+']').parentNode.parentNode.style.display = "none";
}
}
function showFields(key) {
hideAllFields()
for(var i = 0; i < required_financial_fields[key].length; i++) {
document.querySelector('[name='+required_financial_fields[key][i]+']').parentNode.parentNode.style.display = "block";
}
}
var category = document.getElementById('id_category');
showFields(category.value)
category.addEventListener('change', function() {
showFields(this.value)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment