Use Conditional Logic in your Custom Gravity Forms JavaScript

Say you’re writing some custom JavaScript for your Gravity Forms form display and need to compare a form value with a conditional logic rule from a feed or elsewhere. Gravity Forms has some JavaScript already written to do the comparison for you, housed in the conditional_logic.js file. Although this file is only enqueued by default when a field on the form itself contains conditional logic, you can use the gform_enqueue_scripts hook to enqueue it based on your parameters. Then simply create your own “conditional logic” rule in an Array (using the proper format: fieldId, operator, value) and you’ll be able to pass the form ID and your rule to the gf_is_match function to effortlessly compare any field on your form with another value. Here’s an example: var rule = ['fieldId': '1', 'operator':'>', 'value':'10']; if ( gf_is_match( formId, rule ) ) { //handle your business } Enjoy! 🙂

Questions? Email Me