gpt4 book ai didi

javascript - 如何将 ComboBox 中的用户输入限制为仅 SAPUI5 中的模型数据

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:59:49 27 4
gpt4 key购买 nike

我有一个场景,我想限制用户只能输入仅加载到组合框的文本,如 MultiComboBox 示例所示。 [请注意,这不是我的 jsbin。请在此线程中发布您的答案]

http://jsbin.com/sicixisozi/edit?html,js,output

在上面的示例中,用户只能输入组合框中出现的字符,例如输入“s”将提示无效输入并阻止用户输入。但是,我没有使用 MultiComboBox,而是将使用 ComboBox,并且在默认 SAPUI5 ComboBox

中找不到此功能

http://jsbin.com/xenidoh/embed?html,output

var mcb = new sap.m.ComboBox({  

如上例所示,用户不受限制,可以向组合框输入任何内容。有什么建议我可以在 MultiComboBox 中将相同的功能实现到 ComboBox 吗?

最佳答案

在组合框的更改事件中,检查 oComboBox.getSelectedkey() 是否不为 null 或为空。如果为空,则表示用户没有选择正确的值,因此返回错误。

oComboBox.attachChange(function(oEvent){
var newval = oEvent.getParameter("newValue");
var key = oEvent.getSource().getSelectedItem();


if (newval !== "" && key === null){
oEvent.getSource().setValue("");
oEvent.getSource().setValueState("Error");
}else{
oEvent.getSource().setValueState("None");
}

});

或者如果您使用的是 XML View - 将函数添加到 change=""其中 oComboBox 是您的组合框。

http://jsbin.com/vupehukena/1/edit?html,output

关于javascript - 如何将 ComboBox 中的用户输入限制为仅 SAPUI5 中的模型数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42965929/

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