sapui5 - 显示通用消息而不是特定于约束的消息
问题描述
对于具有minLength: 2
和maxLength: 10
符号约束的输入字段,如果您要引入 11 个符号,您将收到一条静态错误消息,指出它是“无效条目”。
以下Input
字段:
<Input value="{
path: 'modelExample>/Example1',
type: 'sap.ui.model.type.String',
constraints: {
minLength: 2,
maxLength: 10
}
}"/>
如何修改输入字段,以便将错误消息更改为:“您的输入只能介于 2 到最多 10 个符号之间”?
解决方案
您必须在某处Error
手动设置 valueState 而不是让框架自动生成消息。
在这里,您可以看到消息根据输入值正确显示:
sap.ui.require([
"sap/ui/core/Core"
], Core => Core.attachInit(() => sap.ui.require([
"sap/ui/core/mvc/XMLView",
], async (XMLView) => {
"use strict";
const control = await XMLView.create({
definition: `<mvc:View xmlns:mvc="sap.ui.core.mvc"
xmlns="sap.m"
xmlns:core="sap.ui.core"
core:require="{ ThatTypeString: 'sap/ui/model/type/String' }">
<App>
<Page showHeader="false" class="sapUiResponsiveContentPadding">
<Input width="17rem" value="{
value: '1234567890',
type: 'ThatTypeString',
constraints: {
minLength: 2,
maxLength: 10
}
}"/>
</Page>
</App>
</mvc:View>`,
height: "100%",
});
Core.getMessageManager().registerObject(control, true);
control.placeAt("content");
})));
<script id="sap-ui-bootstrap"
src="https://openui5.hana.ondemand.com/resources/sap-ui-core.js"
data-sap-ui-libs="sap.ui.core,sap.m"
data-sap-ui-theme="sap_fiori_3"
data-sap-ui-async="true"
data-sap-ui-compatversion="edge"
data-sap-ui-excludejquerycompat="true"
data-sap-ui-xx-waitfortheme="init"
></script>
<body id="content" class="sapUiBody sapUiSizeCompact"></body>
请参阅文档主题验证消息部分“自动创建的消息”。大多数情况下,在文件中设置"handleValidation": true
为就足够了。"sap.ui5"
manifest.json
不要手动设置 valueState,而是确保框架自动设置消息。
推荐阅读
- asp.net-core - 提供了无效的请求 URI。请求 URI 必须是绝对 URI,或者必须设置 BaseAddress。在 Blazor
- python - 迭代和更改 python numpy 矩阵列的值
- xcode - Xcode 11.1:未显示测试指标
- javascript - 如何使用带有钩子的反应功能组件测试句柄函数调用
- matlab - 在 MATLAB 中读取 imageSet 的描述/标签
- angular - Angular:如何根据选择另一个日期输入来验证日期输入
- flutter - 如何在 Flutter 中将平面颜色导入我的项目?
- rundeck - Rundeck 是否提供插件以在启动时从文件加载作业?
- node.js - Mongodb mongoose 模型将它们全部从 index.js 文件中导出
- python - 有没有办法找出两个文件的哈希值?