我想在类型设置为 Number 时在输入字段中设置验证并使用 sapui5 设置 maxlength。但它不起作用。
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 不兼容。如果输入类型设置为 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 - 如果输入类型设置为 Number 如何使用 sapui5 设置 maxlength,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41548290/