我正在使用表单validaiton的bootstrap验证插件。
点击'取消'按钮没有更改任何表单字段的值,它应该关闭页面并带我到访问此页面之前的页面。
我清除了几个字段并点击了取消按钮。旧值重置但仍显示验证错误。
Html代码:
<form class="profile_settings" id="profile_settings" data-toggle="validator" role="form">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<input type="text" required="required" name="first_name" id="first_name" class="form-control firstname input-lg input-border first_name input-style" placeholder="First name" value="">
</div>
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 ">
<input type="text" name="last_name" id="last_name" class="form-control lastname input-lg input-border last_name input-style" placeholder="Last name" value="">
</div>
<button type="submit" class="profile-save-btn" style="padding-left: 37px;"><img src="images/savetick.png"><span class="profile-save green-separator">Save</span>
</button>
<button type="reset" class="profile-cancel-btn"><img src="images/cancel.png"><span class="profile-cancel">Cancel</span>
</button>
</div>
</form>
Js代码:
<script>
$("#profile_settings").bootstrapValidator({
message : 'This value is not valid',
container : 'tooltip',
feedbackIcons : {
valid : 'glyphicon glyphicon-ok',
invalid : 'glyphicon glyphicon-remove',
validating : 'glyphicon glyphicon-refresh'
},
fields : {
first_name : {
container : 'popover',
validators : {
notEmpty : {
message : 'First name is required and cannot be empty'
},
regexp : {
regexp : /^[a-z\s]+$/i,
message : 'First name can only consist of alphabetical characters'
},
stringLength : {
min : 3,
message : 'first name must be more than 3 characters '
}
}
},
last_name : {
container : 'popover',
validators : {
notEmpty : {
message : 'Last name is required and cannot be empty'
},
regexp : {
regexp : /^[a-z\s]+$/i,
message : 'Last name can only consist of alphabetical characters'
},
stringLength : {
min : 3,
message : 'Last name must be more than 3 characters '
}
}
},
}
}).on('success.form.bv', function(e) {
e.preventDefault();
profileInfoSubmit(this);
});
});
$('.profile-cancel-btn').click(function() {
var previousUrl = document.referrer;
//window.location=previousUrl;
});
</script>
请建议我。