我真的很难做到这一点。
我试图为我的雇主做的是提交一个有效的表单,问题是基于提交的字段弹出表单(使用fancybox版本3- http://fancyapps.com/fancybox/3/)的条件是,当地点是苏格兰和最终金额超过up 4,550(第二个选择框上的选项2)。
我使用$(this).validate ()运行验证(因为页面上有多个表单)。然后,我想控制submitHandler,并根据条件将fancybox作为confirmation运行,这样当单击fb.box中出现的按钮时,表单就会提交。
我觉得我没有传递一些变量或者遗漏了一些重要的东西。我知道有一些其他的方法可以实现这一点,但由于fancybox提供的样式选项,这是首选的方法,请帮助,我已经绞尽脑汁2天试图做到这一点。
我的最后一种方法是从经过验证的表单获取变量并将其传递到fancybox中,然后从框中提交(不理想,但可能是唯一的方法)。如果您想查看表格,请访问:
$('form').each(function() {
$(this).validate({
rules:{
location:"required",
debtAmount:"required",
incomeStatus:"required",
livingStatus:"required",
assets:"required",
fullname:{
required:true,
minlength:3
},
phonenumber:{
required:true,
minlength:11,
maxlength:11
},
email:{
required:true,
emailvalidate:true
},
gridCheck:"required"
},
messages:{
location:"Please select what region you live in",
debtAmount:"Please select your approximate debt level",
incomeStatus:"How do you recieve your income",
livingStatus:"What's your current living status",
assets:"Please select an option",
fullname:"Please enter you full name",
phonenumber:"Please enter a valid phone number",
email:"Please enter a valid e-mail address",
gridCheck:"We require your consent to submit your enquiry"
},
submitHandler: function(form) {
// some other code
// maybe disabling submit button
// then
var location = $('[name=location]').val();
var debtAmount = $('[name=debtAmount]').val();
var incomeStatus = $('[name=incomeStatus]').val();
var livingStatus = $('[name=livingStatus]').val();
var assets = $('[name=assets]').val();
if(location == 'Scotland'){
$.fancybox.open({
src :
'<div class="container"><div class="row"><div class="col"><h1 class="text-center">Thanks for you Enquiry</h1></div></div><div class="row"><div class="col text-center><p>Based on the information you have submitted, an IVA may not be suiteable.</p><p>There are many ways in which we can still help and we work with a panel of debt advice companies that could stilll help.</p><p>Your data is important to us and we just want to maek sure you are happy for you to refer you detaisl for a more suitable soluiotion.<p></div></div><div class="row"><div class="col-md-6 col-sm-12"><button data-value="0" data-fancybox-close class="btn">I need a bit more time</button></div><div class="col-md-6 col-sm-12"><button data-value="1" data-fancybox-close class="btn">Sure that is ok</button></div></div></div>',
type : 'inline',
opts : {
afterLoad: function( instance, current, e) {
var button = e ? e.target || e.currentTarget : null;
var value = button ? $(button).data('value') : 0;
if(value == 1){
alert():
}
}
}
})
}
else {
//$(form).submit();
}
}
});
}发布于 2018-06-28 17:13:04
请在下面尝试,
<input type="hidden" value="0" name="is_validated" id="is_validated">
submitHandler。submitHandler: function(form) { //其他一些代码//可能禁用了提交按钮//然后var location = $('name=location').val();var debtAmount = $('name=debtAmount').val();var incomeStatus = $('name=incomeStatus').val();var livingStatus = $('name=livingStatus').val();var assets = $('name=assets').val();if(location == 'Scotland‘&& $('#is_validated').val() != '1'){ // MODIFIED $.fancybox.open({ src:’谢谢您Enquiry
从花哨框中的两个按钮中删除属性data-fancybox-close,并添加类data-fancybox-click,然后向此按钮添加单击事件,并相应地更改is_validated的值。如果用户单击了按钮Sure that is ok,则将is_validated值设置为1并再次单击触发表单提交。
仅当为(location == 'Scotland' && $('#is_validated').val() != '1')时,才会显示花式框
https://stackoverflow.com/questions/51075085
复制相似问题