Skip to content

Instantly share code, notes, and snippets.

@Shelob9
Created February 25, 2019 18:37
Show Gist options
  • Save Shelob9/6b9691f1d6cd61323b6c1aad675be8c6 to your computer and use it in GitHub Desktop.
Save Shelob9/6b9691f1d6cd61323b6c1aad675be8c6 to your computer and use it in GitHub Desktop.
/**
* Run callback function after a Caldera Forms conditional logic event has transpired
*
* Required Caldera Forms 1.8.0 or later.
*/
jQuery(document).on('cf.form.init', function (event, data) {
var state = data.state;
//runs whenever a field of this form id enabled
state.events.attatchEvent( 'cf.enable', function(fieldIdAttr, formIdAttr){
console.log(fieldIdAttr, formIdAttr);
});
//runs whenever a field of this form id disabled
state.events.attatchEvent( 'cf.disabled', function(fieldIdAttr, formIdAttr){
console.log(fieldIdAttr, formIdAttr);
});
//runs whenever a field of this form id hiden
state.events.attatchEvent( 'cf.hide', function(fieldIdAttr, formIdAttr){
console.log(fieldIdAttr, formIdAttr);
});
//runs whenever a field of this form id shown
state.events.attatchEvent( 'cf.show', function(fieldIdAttr, formIdAttr){
console.log(fieldIdAttr, formIdAttr);
});
});
@pless84
Copy link

pless84 commented Apr 23, 2019

I get this: state.events.attatchEvent is not a function

@mdorchain
Copy link

mdorchain commented Sep 2, 2019

@lavert
Copy link

lavert commented Oct 9, 2019

@mdorchain did it work for you like that, state.events().attachEvent()?

I got the same initial error as pless84 mentioned, your fix removed that error, but I'm not seeing any of them fire in the console when fields are conditionally displayed or removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment