Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

For function e.preventDefault() i am getting error: "Undefined is not a function". Do i need to include some library?

Hello UI5 people,

I was trying to put validation on my textfield so that it accepts only numbers. I found following code in this community an tried to use it:

var textbox = new sap.ui.commons.TextField("data",{}); 


  var key_codes = [48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 0, 8]; 

            if (!($.inArray(e.which, key_codes) >= 0)) { 





But on the line "e.preventDefault" i am getting error : "Undefined is not a function"

So does this mean i need to include some library ?

I tried including sap.ui.base.Event class but it gives me error "could not load"

What do i need to do??

Please help

Thank you,



Former Member

Hello Chetna,

your coding should work. It is enough to include the sap.ui.commons library for your case in the bootstrap tag.

I just tested it on jsfiddle (OpenUI5 TextField with Only Numbers - JSFiddle) with the newest versions of Chrome, Firefox and IE.

What browser and version you are using? Maybe you can check if the example on jsfiddle works for you too. If yes, then you can check your coding agains the example coding.

Best regards,


1 View this answer in context
Not what you were looking for? View more on this topic or Ask a question