jaywcjlove / jaywcjlove/validator.js

表单提交自动刷新?

Open
#41 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
554
Forks
114
PR merge metrics
No merged PRs in 30d

Description

callback函数中,没有validator的错误,函数会执行,但会把页面刷新。例如下面的代码,无法显示弹窗(modal1和modal2都不行),并且会把表单的内容重置,类似于页面刷新,请问如何解决这个问题,组织刷新?
`var validator = new Validator('form1',[
{
name:"temperature",
display:"请输入正确的体温值",
rules: 'is_money'
},{
name:"BMI",
display:"请输入正确的BML值",
rules: 'is_money'
}
],function(obj,evt){

var errors_elm = document.getElementById('error_msg');
errors_elm.style.display = 'none';
console.log(evt);
console.log(obj);
if(obj.errors.length>0){
// 判断是否错误
var error_str = '';
for (var i = 0; i < obj.errors.length; i++) {
error_str += i+1 + ':' + obj.errors[i].message + ';
';
}
errors_elm.style.display = "block";
errors_elm.innerHTML = error_str;

$("#tipModal2").modal('show');
}else{
var CRE = $("input[name='CRE']").val();

var flag = true;
if($.trim(CRE) < 64 || $.trim(CRE) > 104){
flag = false;
$('#CRE_tip').show();
}

if(flag){
$.ajax({
type: "POST", //提交的方法
url: "/get_result/", //提交的地址
data: $('#form1').serialize(),// 序列化表单值
async: false,
error: function (request) { //失败的话
//alert("Connection error");
$('#modal1').modal('show');
},
success: function (result) { //成功
console.log(result); //就将返回的数据显示出来
$('#modal2').modal('show');
}
});
return false;
}else{
// alert("hhh");
$("#tipModal").modal('show');
}
}
});`

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the inline Validator callback for form1 and trace how the form submission event reaches it. Reproduce the reported case with a valid form, then inspect the callback's return path and the modal/ajax branches. Done means the callback displays the intended modal without refreshing or resetting the form.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, jquery
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.