bookmark_bordergform_post_conditional_logic_field_action

Description

This JavaScript hook can be used to perform custom actions when a field is displayed or hidden by conditional logic on the frontend.

Usage

<script>
gform.addAction('gform_post_conditional_logic_field_action', function (formId, action, targetId, defaultValues, isInit) {
    // do stuff
});
</script>

Parameters

  • formId integer

    The ID of the current form.

  • action string

    The current conditional logic action. Possible values: show or hide.

  • targetId string

    The ID selector for the field container (li) in the format #field_{formId}_{fieldId} e.g. #field_10_2

  • defaultValues string|array

    The field default values.

  • isInit boolean

    True when the form is initially displayed, otherwise false.

Examples

### 1. Reset Coupon field

The following example shows how you can reset the coupon field when hidden by conditional logic.

gform.addAction('gform_post_conditional_logic_field_action', function (formId, action, targetId, defaultValues, isInit) {
    if (!isInit && action == 'hide') {
        var target = jQuery(targetId),
            coupon_items = target.find('tr.gf_coupon_item');

        if (coupon_items.length) {
            coupon_items.remove();
            target.find('input[type=hidden]').val('').change();
        }
    }
});

Placement

Your code snippet can be placed in a HTML field on your form or in a theme custom JavaScript file.

Source Code

This hook is located in js/conditional_logic.js