Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
161
rated 0 times [  162] [ 1]  / answers: 1 / hits: 21359  / 8 Years ago, mon, january 9, 2017, 12:00:00

I want to set validation in input field when type is set to Number and set maxlength using sapui5. But it is not working.



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
}
}

})]
});

More From » sapui5

 Answers
8

Description of method setMaxLength of sap.m.Input from API:


This parameter is not compatible with the input type sap.m.InputType.Number. If the input type is set to Number, the maxLength value is ignored.


So it means you have to find other way how to do this. For example, when you use sap.m.InputType.Tel format instead, maxLength method works:


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

Here is interactive example.


EDITED 17:30 090117:


I edited previous posted code allowing to type just numbers as you wanted (Please, try 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');

[#59414] Friday, January 6, 2017, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lailab

Total Points: 706
Total Questions: 102
Total Answers: 95

Location: Falkland Islands
Member since Mon, Jul 13, 2020
4 Years ago
;