Last active
March 2, 2021 10:24
-
-
Save svondervoort/583f4e1592bf079c43a8ea471eaaec00 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
// Call this function with a form as parameter everytime an input changes | |
function checkConditions(form) { | |
let conditions = []; | |
form.find('div[data-conditional] :input').each(function(){ | |
let value = $(this).val(); | |
conditions.push(value); | |
}); | |
$.each(conditions, function( index, value ) { | |
form.find('div[data-condition]').hide(); | |
form.find('div[data-condition="' + value + '"]').each(function(){ | |
$(this).show(); | |
}); | |
}); | |
} | |
// Example: | |
const form = $('form[name="my-form"]'); | |
form.find(':input').change(function(){ | |
checkConditions(form); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment