Skip to content

Commit

Permalink
gf-recalculate-on-image-wrapper-click.js: Added snippet to ensure c…
Browse files Browse the repository at this point in the history
…alculations as soon as we click the image wrapper.
  • Loading branch information
saifsultanc authored Jan 14, 2025
1 parent ed8d79c commit a6145f9
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions experimental/gf-recalculate-on-image-wrapper-click.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Gravity Perks // Gravity Forms // Trigger calculations on click of image for Image Choice
* https://gravitywiz.com/
*
* This snippet is needed to work around a bug in Gravity Forms 2.9 where calculations are not
* re-processed when the actual image of an Image Choice is clicked. It works fine if you click on
* the label or the checkbox/radio itself.
*
* Instructions:
*
* 1. Install this snippet with our free Custom JavaScript plugin.
* https://gravitywiz.com/gravity-forms-code-chest/
*/
$( '#gform_GFFORMID input:checkbox, #gform_GFFORMID input:radio' ).on( 'change', function (event) {
var $target = $( event.target );
if ( !$target.closest( '.gfield-image-choice-wrapper-inner' ).length ) {
return;
}

var _GFCalc = rgars( window, 'gf_global/gfcalc/{0}'.gformFormat( GFFORMID ) );
_GFCalc.runCalcs( GFFORMID, _GFCalc.formulaFields );
});

0 comments on commit a6145f9

Please sign in to comment.