在 jQuery 更改为隐藏字段后触发 Gravity Forms 中的表单更新 [英] Trigger a form update in Gravity Forms after jQuery change to hidden field

查看:20
本文介绍了在 jQuery 更改为隐藏字段后触发 Gravity Forms 中的表单更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简而言之:是否有 javascript 函数或钩子来触发对重力形式的更新,以便执行条件逻辑?

原问题:

我正在使用 Gravity Forms 并创建了一个on change"事件

$('#gform_1').find('.gfield_date_dropdown_month select').change(function () {var 月 = $(this).val();$('input#input_1_6').val(month).change();});

在此事件之后,我希望 Gravity Forms 检查/更新表单,以便条件逻辑"生效.正在执行到相关字段.

我检查了

解决方案

Gravity Forms 条件由 clickchange 事件触发,具体取决于字段的类型.您可以使用 .change() 方法手动触发 change 事件.

注意这是行不通的,因为条件没有绑定到您附加更改事件的字段,因此您必须在执行的字段上触发 .change() 有条件.假设字段 1_6 是触发条件的字段:

$('#gform_1').find('.gfield_date_dropdown_month select').on('change', function(){var 月 = $(this).val();$('#input_1_6').val(month).change();});

其他一些小笔记,考虑使用 .on('change', function(){} 而不是 .change(function(){} 因为它会触发在动态元素上 - 以及在 #input_1_6 之前不需要 input 因为它已经是一个唯一的元素.

干杯!

IN SHORT: Is there a javascript function or hook to trigger an update to a Gravity Form so that the conditional logic is executed?

ORIGINAL QUESTION:

I'm using Gravity Forms and I have created an "on change" event

$('#gform_1').find('.gfield_date_dropdown_month select').change(function () {
      var month = $(this).val();
      $('input#input_1_6').val(month).change();
});

After this event I would like Gravity Forms to check/update the form so that the "Conditional Logic" is being executed to related fields.

I have checked the hooks on https://docs.gravityforms.com/category/extending-gravity-forms/hooks/javascript but I can't find a hook that I can use for this purpose. Any ideas?

UPDATE: The field that is changed (#input_1_6) is "hidden". This seems to be the problem. When I make this field visible it does work! So a change to a "hidden" field does not seem to trigger the update to the form. If I would have a function that would trigger this update I could add it to my jQuery function.


Some background information on this issue. I want a field to become visible when a certain month is selected in a date field. Since Gravity Forms does not support "Conditional Logic" based on a date field I want to update a hidden field with the "month value" and then use that value for the "Conditional Logic" on a related field.

解决方案

Gravity Forms conditionals are triggered with the click or change events, depending on the type of field. You can manually trigger the change event with the .change() method.

Note this isn't working because the conditional isn't tied to the field you attached a change event to, so you have to trigger .change() on the field that does have conditionals. Assuming field 1_6 is the field that triggers conditionals:

$('#gform_1').find('.gfield_date_dropdown_month select').on('change', function(){
    var month = $(this).val();
    $('#input_1_6').val(month).change();
});

Some other small notes, consider using .on('change', function(){} instead of .change(function(){} as it will trigger on dynamic elements - as well as you don't need input before #input_1_6 since it's already a unique element.

Cheers!

这篇关于在 jQuery 更改为隐藏字段后触发 Gravity Forms 中的表单更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆