[英]How to prevent alpaca from generating radio field when the search select has 3 or less options
我有一个 div 和一个以下 javascript:
let usersNotContributingIds = [ 19, 20, 21 ];
let usersNotContributingNames = [ "Flavius K.", "Pogchamp", "Lazy Gopnik" ];
let contributorToBeAddedId; // the value that will be used for further actions
$("#alpaca-search-contributing-users").alpaca({
data: null,
schema: {
type: "object",
enum: usersNotContributingIds,
},
options: {
name: "pls",
label: 'Contributor Fullname',
optionLabels: usersNotContributingNames,
helper: "Select user sou want to add as a contributor",
id: "select2-search",
focus: false,
events: {
change: function() {
console.log(this.getValue().value);
contributorToBeAddedId = this.getValue().value
},
focus: function() {
console.log(this.name);
},
blur: function() {
console.log(this.name + ": blur");
},
ready: function() {
console.log(this.name);
}
},
},
postRender: function(control) {
$('#select2-search').select2();
}
});
显然,我想获取新设置的值,或者无论如何访问所选值并使用它。 例如 AJAX 和一个按钮。 问题是,当我有 3 个或更少的选项时,Alpaca 不会将该字段呈现为搜索,而是呈现为无线电的东西,并且 this.getValue this.getValue()
是 null。
有没有办法强制羊驼不使用无线电按钮? 我不想使用它们,即使我只有一个选项。 文档只是迅速指出,如果有 3 个或更少的选项,它将生成单选按钮而不是 select,但它没有说明这一事实,它破坏了一切,我将无法以与带有 select 字段。
如果我做的事情效率低下或错误,请告诉我,我是 Alpaca 的新手,我只想要一个整洁的 select 下拉列表和搜索,我可以用它从任何长度的列表中选择用户。 另外,我希望“null”或“none”选项不存在。
要渲染您的 select 组件,您应该使用选项type
并将其设置为"select"
。
该值的问题是因为您使用错误,要获取 alpaca 中的值,您只需执行this.getValue()
并且无需添加.value
。
仅供参考:如果您看到错误“此字段应具有 Flavius K.、Lazy Gopnik、Pogchamp 中的值之一。当前值为:19 ”您应该更新您的枚举数组以使用字符串而不是整数let usersNotContributingIds = [ "19", "20", "21" ];
.
这是一个工作小提琴。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.