![](/img/trans.png)
[英]JQuery Form Validation: Error Message not displayed when there is escaped JSON
[英]Custom jQuery not triggered/working after gravity form default validation error message gets displayed
我正在添加自定義 jQuery 以根據條件邏輯顯示某些字段。 例如:當“業務類型”字段值選擇為公司時,將顯示“公司名稱”和“公司網站”字段。 否則,這些字段將被隱藏。
一切正常,直到顯示重力表單默認驗證消息。 當出現驗證錯誤消息時, #input_2_8
change 事件不會被觸發。 拜托,有人可以幫我解決這個問題嗎?
根據業務類型值顯示/隱藏公司字段
jQuery(document).ready(function($){
//Hide the fields by default
$('#input_2_9').css('display','none');
$('#input_2_10').css('display','none');
$('#input_2_8').on('change', function(e){
var self = $(this);
if(self.val() === 'Business') {
$('#input_2_9').fadeIn();
$('#input_2_10').fadeIn();
}else{
$('#input_2_9').fadeOut();
$('#input_2_10').fadeOut();
}
});
});
如果有人想看看表格,那么這里是網址: https : //gems-precious.com/form/
提前致謝!
試試這個代碼
jQuery(document).ready(function($){
//Hide the fields by default
jQuery('#input_2_9').css('display','none');
jQuery('#input_2_10').css('display','none');
jQuery('#gform_submit_button_2').on('click', function(e){
var self = jQuery('#input_2_8 :selected').text();
if(self == 'Business') {
jQuery('#input_2_9').fadeIn();
jQuery('#input_2_10').fadeIn();
}else{
jQuery('#input_2_9').fadeOut();
jQuery('#input_2_10').fadeOut();
}
});
});
Gravity 驗證字段后,Gravity 表單將重新渲染所有字段,因此您編寫的腳本代碼不會綁定到新元素。 所以你需要再次綁定它(驗證后)或使用這個鈎子gform_post_render
。
如下:
jQuery(document).on('gform_post_render', function(){
console.log('gform rendered');
//Your custom scripts code
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.