Last active
June 8, 2018 16:18
-
-
Save jasonyingling/466f214819899e0f7087de29b2927d70 to your computer and use it in GitHub Desktop.
DDSlick with Gravity Forms
This file contains 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
$('.gfield select').each(function(e) { | |
// Hide the select element | |
$(this).css('display', 'none'); | |
// clone the select element | |
clone = $(this).clone(); | |
// append the cloned select after the first select | |
$(this).after(clone); | |
// store the original select ID | |
var selectID = $(this).attr('id'); | |
// Call ddslick on the cloned select | |
$(clone).ddslick({ | |
onSelected: function(data) { | |
// onSelected get the length of value of the selected option | |
var value = $('#' + selectID + ' .dd-selected-value').val().length; | |
// if the value is set (exists) | |
if (value > 0) { | |
// update the original select element with the chosen value. Fire a change to make it run condtional logic | |
$('select#' + selectID) | |
.val(data.selectedData.value) | |
.change(); | |
} | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment