Skip to content

Instantly share code, notes, and snippets.

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 mishterk/4442055ee0d814c36381bfc50295e868 to your computer and use it in GitHub Desktop.
Save mishterk/4442055ee0d814c36381bfc50295e868 to your computer and use it in GitHub Desktop.
Calculated field enhancements in Advanced Forms Pro version 1.6.6. For more info see https://hookturn.io/2019/11/advanced-forms-pro-calculated-field-enhancements/
// This will intercept the rendered calculated field and insert the markup
// into an element with the id `#preview-container`
acf.addAction( 'af/field/calculated/value_updated', function( value, field, form ) {
$('#preview-container').html(value);
});
// You may intercept the return values of specific fields by field name
acf.addAction( 'af/field/calculated/value_updated/name=FIELD_NAME', function( value, field, form ) {
// …
});
// You may also intercept the return values of specific fields by field key
acf.addAction( 'af/field/calculated/value_updated/key=FIELD_KEY', function( value, field, form ) {
// …
});
// This is the simplest format available and will trigger the update for
// all calculated fields on the page
acf.doAction( 'af/field/calculated/update_value' );
// You may target specific fields by field name
acf.doAction( 'af/field/calculated/update_value/name=FIELD_NAME' );
// You may also target specific fields by field key
acf.doAction( 'af/field/calculated/update_value/key=FIELD_KEY' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment