与 JSONModel 相比,输入验证不适用于 v2.ODataModel [英] Input validation not working with v2.ODataModel in contrast to JSONModel
问题描述
在当前项目中,我有一个 视图上的 SimpleForm.在此视图上绑定 JSONModel,validateValue
函数在我的输入字段上运行良好.输入字段的约束定义如下:
In the current project, I have a SimpleForm on a view. Binding a JSONModel on this view, the validateValue
function is working fine on my input field. The constraints on the input field are defined as follows:
<Input value="{
path: '/carrId',
type: 'sap.ui.model.type.String',
constraints: {
// ...
}
}"/>
将模型更改为 ODataModel
不会触发 validateValue
,并且如果约束不匹配,该字段不会标记为红色.
Changing the model to an ODataModel
doesn't fire the validateValue
and the field is not marked with red if the constraints are not matched.
视图已在消息管理器中注册.
The view is registered at the message manager.
我是否必须通过实施 change
事件来实施验证,或者错误在哪里?
Do I have to implement the validation by implementing a change
event or where is the mistake?
推荐答案
将
替换为与您的sap.ui.model.type.String
carrId
的 EDM 类型相对应的类型.例如.使用sap.ui.model.odata.type.String
如果元数据中有Type=Edm.String"
.请注意,constraints
设置也不同.
Replace
with the type corresponding to the EDM type of yoursap.ui.model.type.String
carrId
. E.g. withsap.ui.model.odata.type.String
if it has theType="Edm.String"
in metadata. Note that theconstraints
settings are also different.
为了真正允许将用户输入从 UI 传输回模型,从而自动触发 parseValue
和 validateValue
,绑定mode 需要是TwoWay
(v2.ODataModel
的默认绑定模式是OneWay
*).
In order to actually allow transferring the user input from the UI back to the model, and thus triggering parseValue
and validateValue
automatically, the binding mode needs to be TwoWay
(The default binding mode of v2.ODataModel
is OneWay
*).
打开
manifest.json
将 /sap.ui5/models/
设置为 TwoWay"
:
Set /sap.ui5/models/<modelName>/settings/defaultBindingMode
to "TwoWay"
:
{
"dataSource": "MyV2ODataSource",
"settings": {
"defaultBindingMode": "TwoWay",
"preliminaryContext": true
},
"preload": true
}
这篇关于与 JSONModel 相比,输入验证不适用于 v2.ODataModel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!