gform_reset_pre_conditional_logic_field_action

Description

This JavaScript hook can be used to prevent the field value being reset to its default value when hidden by conditional logic on the frontend.

Please note fields which are hidden by conditional logic when the form is submitted will not be saved when the entry is saved.

Usage

<script>
gform.addFilter('gform_reset_pre_conditional_logic_field_action', function (reset, formId, targetId, defaultValues, isInit) {
    // do stuff
    return reset;
});
</script>

Parameters

  • reset boolean

    Determines if the field values should be reset to default when the field is hidden. Default is true.

  • formId integer

    The ID of the current form.

  • 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. Prevent all field values being reset

The following example shows how you can prevent the field values being reset to default when the field is hidden by conditional logic.

<script>
gform.addFilter('gform_reset_pre_conditional_logic_field_action', function (reset, formId, targetId, defaultValues, isInit) {
    return false;
});
</script>

Placement

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

Source Code

This filter is located in js/conditional_logic.js

Since

This filter was added in Gravity Forms 2.0.7.1.