Skip to content

Instantly share code, notes, and snippets.

@jasonyingling
Last active June 8, 2018 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonyingling/466f214819899e0f7087de29b2927d70 to your computer and use it in GitHub Desktop.
Save jasonyingling/466f214819899e0f7087de29b2927d70 to your computer and use it in GitHub Desktop.
DDSlick with Gravity Forms
$('.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