gpt4 book ai didi

javascript - 如何将 id 动态传递到 Bootstrap 验证器规则 : remote for a same form input field? 的 url

转载 作者:行者123 更新时间:2023-11-29 10:29:23 24 4
gpt4 key购买 nike

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' 为远程方法动态传递。

关于javascript - 如何将 id 动态传递到 Bootstrap 验证器规则 : remote for a same form input field? 的 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50134376/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com