簡體   English   中英

搜索select有3個或更少選項時如何防止羊駝產生射電場

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM