与 JSONModel 相比,输入验证不适用于 v2.ODataModel [英] Input validation not working with v2.ODataModel in contrast to JSONModel

查看:59
本文介绍了与 JSONModel 相比,输入验证不适用于 v2.ODataModel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在当前项目中,我有一个 视图上的 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?

推荐答案

  1. sap.ui.model.type.String 替换为与您的 carrId 的 EDM 类型相对应的类型.例如.使用 sap.ui.model.odata.type.String 如果元数据中有 Type=Edm.String".请注意,constraints 设置也不同.

  1. Replace sap.ui.model.type.String with the type corresponding to the EDM type of your carrId. E.g. with sap.ui.model.odata.type.String if it has the Type="Edm.String" in metadata. Note that the constraints settings are also different.

为了真正允许将用户输入从 UI 传输回模型,从而自动触发 parseValuevalidateValue绑定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//settings/defaultBindingMode 设置为 TwoWay":

Set /sap.ui5/models/<modelName>/settings/defaultBindingMode to "TwoWay":

{
  "dataSource": "MyV2ODataSource",
  "settings": {
    "defaultBindingMode": "TwoWay",
    "preliminaryContext": true
  },
  "preload": true
}


* 参见绑定模式:一次性绑定,单向, 和双向绑定

这篇关于与 JSONModel 相比,输入验证不适用于 v2.ODataModel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆