gform_post_conditional_logic_field_action

gform_post_conditional_logic_field_action

DescriptionUsageParametersExamples1. Reset Coupon field2. Show/Hide the Save & Continue LinkPlacementSource Code

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

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();
}
}
});

2. Show/Hide the Save & Continue Link
This example shows how conditional logic can be used to show and hide the save and continue link at the same time as another field, in this case field 2 of form id 616.
gform.addAction('gform_post_conditional_logic_field_action', function (formId, action, targetId, defaultValues, isInit) {
if (targetId == '#field_616_2') {
if (action == 'show') {
jQuery('#gform_save_616_footer_link').show();
} else {
jQuery('#gform_save_616_footer_link').hide();
}
}
});

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

發表回覆

您的郵箱地址不會被公開。 必填項已用 * 標註