gform/conditional_logic/field_action/end

Description

The gform/conditional_logic/field_action/end event triggers when Gravity Forms finishes applying a conditional logic action (show or hide) to a target field.

Usage

document.addEventListener( 'gform/conditional_logic/field_action/end', function( event, formId, action, targetId, defaultValues, isInit ) {
           // Custom logic here.
});

Parameters

ParameterTypeDescription
eventeventThe event that triggered the conditional logic action.
formIdintThe ID of the form.
actionstringThe action applied to the target field: show or hide.
targetIdstringThe ID of the target field or section the action was applied to.
defaultValuesobjectThe default value(s) restored or applied to the target field, if any.
isInitboolWhether this run is part of the initial page-load conditional logic evaluation, as opposed to a later, user-triggered evaluation.

Examples

Remove stale coupon rows when a field is hidden by conditional logic.

document.addEventListener( 'gform/conditional_logic/field_action/end', function ( event ) {
    var action = event.detail.action,
        targetId = event.detail.targetId,
        isInit = event.detail.isInit;

    if ( ! isInit && action === 'hide' ) {
        var target = document.querySelector( targetId ),
            couponItems = target.querySelectorAll( 'tr.gf_coupon_item' );

        if ( couponItems.length ) {
            couponItems.forEach( function ( item ) {
                item.remove();
            } );

            target.querySelectorAll( 'input[type=hidden]' ).forEach( function ( input ) {
                input.value = '';
                input.dispatchEvent( new Event( 'change' ) );
            } );
        }
    }
});

Source Code

This event is located in assets/js/src/theme/columns/fixed.js

Since

The event was added in Gravity Forms 3.2