My requirement is to have a textbox that can accept only floating point numbers up to two decimals only.
How to fix below problems:
Below is my code:
sap.ui.getCore().setModel(new sap.ui.model.json.JSONModel(), "myModel");
sap.ui.getCore().getModel("myModel").setProperty("/Amount")
var textbox = new sap.m.Input({
valueLiveUpdate: true,
type: "Number",
}).placeAt("content");
textbox.bindProperty("value", {
path: "myModel>/Amount",
type: new sap.ui.model.type.Float({
minIntegerDigits: 1,
maxFractionDigits: 2,
groupingEnabled: false
}, {
minimum: 1,
maximum: 2000
})
});
textbox.attachValidationError(function(e) {
e.getParameter("element").setValueState("Error");
e.getParameter("element").setValueStateText(e.getParameter("message"));
});
textbox.attachParseError(function(e) {
e.getParameter("element").setValueState("Error");
e.getParameter("element").setValueStateText(e.getParameter("message"));
});
textbox.attachFormatError(function(e) {
e.getParameter("element").setValueState("Error");
e.getParameter("element").setValueStateText(e.getParameter("message"));
});
textbox.attachValidationSuccess(function(e) {
e.getParameter("element").setValueState("Success");
});
<!DOCTYPE html>
<html>
<head>
<script src="https://openui5.hana.ondemand.com/resources/sap-ui-core.js" id="sap-ui-bootstrap" data-sap-ui-theme="sap_bluecrystal" data-sap-ui-libs="sap.m"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<div id="content" />
</body>
</html>
答案 0 :(得分:0)
sap.m.MaskInput控件允许用户以特定格式输入数据。
API:https://openui5.hana.ondemand.com/#docs/api/symbols/sap.m.MaskInput.html
示例:http://jsbin.com/haciwexako/1/edit?html,js,output
Demokit:https://openui5.hana.ondemand.com/explored.html#/sample/sap.m.sample.MaskInput/preview
答案 1 :(得分:0)
我确定你已经这样做了,但是你看过documentation samples了吗? 它看起来应该做你想要的。 如果没有,您总是可以编写一个简单的函数来检查输入值与正则表达式的对比。