Created
August 23, 2014 18:09
-
-
Save dennisseah/b44ba616d33400f84f65 to your computer and use it in GitHub Desktop.
SAPUI5: Only allow numeric in sap.ui.commons.TextField
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | |
<script id="sap-ui-bootstrap" | |
type="text/javascript" | |
data-sap-ui-libs="sap.ui.commons" | |
data-sap-ui-theme="sap_bluecrystal" | |
src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js"> | |
</script> | |
<script> | |
jQuery(function() { | |
var oInput = new sap.ui.commons.TextField(); | |
oInput.onAfterRendering = function() { | |
if (sap.ui.commons.TextField.prototype.onAfterRendering) { | |
sap.ui.commons.TextField.prototype.onAfterRendering.apply(this, arguments); | |
} | |
this.$().keydown(function(event) { | |
var ctrlKey = event.ctrlKey; | |
var altKey = event.altKey; | |
var shiftKey = event.shiftKey; | |
var key = event.keyCode; | |
return ( | |
ctrlKey || | |
altKey || | |
( 47 < key && key < 58 && shiftKey === false) || | |
( 95 < key && key < 106 ) || | |
( key === 8) || (key === 9) || | |
( key > 34 && key < 40) || | |
( key === 46) | |
); | |
}); | |
} | |
oInput.placeAt('content'); | |
}); | |
</script> | |
</head> | |
<body class="sapUiBody"> | |
<div id="content"></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment