javascript-如何将ID动态传递给Bootstrap验证程序规则的URL:同一表格输入字段的远程?
作者:互联网
Bootstrap Validator v 0.5.2被重新用于验证模式中的表单(#myForm).
如下所示,当表单加载到模式时,需求是动态地将唯一ID(外键)传递给“远程”规则的“ URL”.
var remoteUrl = "/remoteurl/";
var id = <Foreign key of the record>
$('#myForm').bootstrapValidator({
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
fieldName: {
validators: {
remote: {
url: remoteUrl + id, //dynamically passing id. // but not passing dynamically.
type: 'POST',
message: "This is the message!"
}
}
}
}
});
问题:
在模式加载中,“ id”成功地动态传递到表单中.不过,除非重新加载页面,否则“ bootstrapValidator”会将第一个传递的“ id”获取到表单中.
解决方法:
找到了解决方案!
添加一个隐藏的输入字段以添加外键.
<input type="hidden" value="" name="foreignKey" id="foreignId">
并且,将外键动态传递给该字段.
$('#foreignId').val(id);
然后,如下
fieldName: {
validators: {
remote: {
url: remoteUrl,
data: function(validator, $field, value) {
return {
foreignKey: validator.getFieldElements('foreignKey').val()
};
},
type: 'POST',
message: "This is the message!"
}
}
}
现在,它对我有用. “ Id”是为远程方法动态传递的.
标签:twitter-bootstrap-3,jqbootstrapvalidation,javascript,bootstrapvalidator,bootstra 来源: https://codeday.me/bug/20191109/2011282.html