java - 在表单验证期间值为空时也会显示错误消息
问题描述
我遇到的问题实际上甚至可以在此处的官方 SmartGWT 演示中看到:https ://www.smartclient.com/smartgwt/showcase/#form_validation_regexp
如果您不输入任何内容(将字段留空)并按验证,则不会显示任何错误。对于所需的值,即使该字段为空,我也需要显示错误。
我将我的验证器设置为:
RegExpValidator regExpValidator = new RegExpValidator();
regExpValidator.setExpression("^[0-9A-Z_]{7,12}$");
regExpValidator.setErrorMessage("Code must contain capital letters and numbers");
codeField.setValidators(regExpValidator);
现在这个表达式不匹配一个空字符串。但是,我在验证时没有错误。
如何在表单中显示空所需值的错误?
解决方案
您可以直接使用 setError 方法。并返回表格。
if(codeField.getText().trim().isEmpty()){
codeField.setError("The Code must not be Empty.");
return;
}
这将返回表单并验证空字符串。
推荐阅读
- c# - 为什么图表不更新
- abp - 如何在 ABP 框架中禁用事务?
- docusignapi - 基于模板将文档添加到信封
- javascript - 使用 jQuery ajax 和 Django 上传文件
- c# - 如何修复数学随机方法组浮动
- javascript - 如何创建创建新 html 文件的函数/方法?
- javascript - 如何使用 Vuejs 中的链接重定向到另一个组件?
- python - 使用 python (tabula) 将 PDF 导出为 csv
- java - 需要帮助使用带括号和 OR 操作的正则表达式
- validation - vee-validate 是否适用于第三方 UI 组件,例如 Primevue?