cancel
Showing results for 
Search instead for 
Did you mean: 

How XML Input field should allow only enter key Numbers in sapui5?

Former Member
0 Kudos

<Label text="Number" />

<Input value="{Num}" type="Number" />

This is dynamic row field in table column.

without particular ID Value.

Example : https://www.cambiaresearch.com/articles/39/how-can-i-use-javascript-to-allow-only-numbers-to-be-ente...

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos
Former Member
0 Kudos

I tried this one. I need without ID value because I am using grid Table ( ID will be generate dynamically) .

former_member227918
Active Contributor
0 Kudos

you can attach browser event, check this,

var oInput = this.getView().byId("inputid");
oInput.attachBrowserEvent("keypress", function(oEvent) {
    var charCode = (oEvent.which) ? oEvent.which : oEvent.keyCode;
    if (charCode != 46 && charCode > 31 &&
        (charCode < 48 || charCode > 57))
        oEvent.preventDefault();
});
Former Member
0 Kudos

I tried this one. I need without ID value call this function because I am using grid Table .

former_member227918
Active Contributor
0 Kudos

you can define onafterrendering function for your table and attach above browser event function for that particular input.

provide your code, and creating input dynamiclly or in xml ?

Former Member
0 Kudos

Thank you for your reply :

But i need like this below url

Allow only enter keyboard numbers in input

Example : https://www.cambiaresearch.com/articles/39/how-can-i-use-javascript-to-allow-only-numbers-to-be-ente...

Former Member
0 Kudos

<Input value="{Num}" type="Number" livechange="onChange"/>

function:onChange(oEvent)

{

myString = oEvent.getSource().getValue();

myString = myString.replace(/\D/g,"");

oEvent.getSource().setValue(myString);

}

Former Member
0 Kudos

Thank you for your reply :

But i need like this below url

Allow only enter keyboard numbers in input

Example : https://www.cambiaresearch.com/articles/39/how-can-i-use-javascript-to-allow-only-numbers-to-be-ente...