我有四个带有标签名称,年龄,城市和电话号码的文本字段,如果它为空,我必须对其进行验证。它应该提醒我加油。如何使用sapui5中的必填字段验证器来验证文本字段?
您可以简单地编写一个获取文本字段并检查其值的函数。
可能看起来像这样:
function validateTextFieldValues() {
// this function gets the first textfield
var nameTextField = sap.ui.getCore().byId("idOfTheTextFieldContaingTheName");
//this function checks its value, you can insert more checks on the value
if(nameTextField.getValue() === "") {
alert("Please enter a name.");
}
// ...
// the same for the other fields
}
然后,您可以在单击按钮时绑定功能,例如在创建按钮时:
new sap.ui.commons.Button({
// your buttonconfiguration
click: function(){
validateTextFieldValues();
}
});
此外,TextField
还有一个名为的属性valueState
。
与事件有关,liveChange
有机会在键入时验证输入:
new sap.ui.commons.TextField({
// your configuration
liveChange: function(){
if(this.getValue() === "")
this.setValueState(sap.ui.core.ValueState.Error);
else
this.setValueState(sap.ui.core.ValueState.Success);
}
});
(https://openui5.hana.ondemand.com/docs/api/symbols/sap.ui.core.ValueState.html)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句