Skip to content

Instantly share code, notes, and snippets.

@jetsloth
Created March 10, 2020 00:48
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 jetsloth/b3e8dc13458cc80fbac951dad7fab4ac to your computer and use it in GitHub Desktop.
Save jetsloth/b3e8dc13458cc80fbac951dad7fab4ac to your computer and use it in GitHub Desktop.
/*///////////////////
JS
Build a simple product visualiser with Gravity Forms Color Picker
Full article at https://jetsloth.com/labs/build-a-simple-product-visualiser-with-gravity-forms-color-picker/
////////////////////*/
<script type="text/javascript">
jQuery(document).bind('gform_post_render', function(e, formId, currentFormPage) {
// Hide all the product images
jQuery( ".gform_body li.preview-area img" ).css('display','none');
// Now show the first image to start with
jQuery( ".gform_body li.preview-area img:eq(1)" ).css('display','block');
// On color swatch click/secltion
jQuery( "li.color-picker-choice " ).click(function() {
// Get index of color selection input
var $radioIndex = jQuery( "li.color-picker-choice ").index(this);
// Refernce the images in the preview
var $imageRef = jQuery( ".gform_body li.preview-area .product");
// Hide all images to start with
$imageRef.css("display","none");
// Show relevant image in reference to click color selection index
$imageRef.eq( $radioIndex ).css("display","block");
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment