gpt4 book ai didi

javascript - 如果输入类型设置为数字如何使用 sapui5 设置最大长度

转载 作者:行者123 更新时间:2023-11-30 11:44:13 24 4
gpt4 key购买 nike

当类型设置为数字并使用 sapui5 设置最大长度时,我想在输入字段中设置验证。但它不起作用。

var Price = new sap.m.HBox({
items:[new sap.m.Label({text:"Per Unit Price",required:true,design:"Bold",width:"110px"}),
new sap.m.Input("Price",{ width:"150px",type:"Number",
value:{
type : 'sap.ui.model.type.Integer',
constraints : {
minLength: 1,
maxLength: 15
}
}

})]
});

最佳答案

来自 API 的 sap.m.Input 方法 setMaxLength 的说明:

此参数与输入类型 sap.m.InputType.Number 不兼容。如果输入类型设置为数字,则忽略 maxLength 值。

所以这意味着你必须找到其他方法来做到这一点。例如,当您改用 sap.m.InputType.Tel 格式时,maxLength 方法起作用:

var oInput = new sap.m.Input("Price",{ 
width:"150px",
type:"Tel",
minLength: 1,
maxLength: 15
});
oInput.placeAt('content');

Here是交互式示例。

编辑 17:30 090117:

我编辑了之前发布的代码,允许您根据需要键入数字(请尝试 here):

    var sNumber = "";
var oInput = new sap.m.Input("Price",{
width:"150px",
minLength: 1,
maxLength: 15,
liveChange : function(oEvent){
var value = oEvent.getSource().getValue();
var bNotnumber = isNaN(value);
if(bNotnumber == false)sNumber = value;
else oEvent.getSource().setValue(sNumber);
},

});
oInput.placeAt('content');

关于javascript - 如果输入类型设置为数字如何使用 sapui5 设置最大长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41548290/

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