【问题标题】:Also show error message when value is empty during form validation在表单验证期间值为空时也会显示错误消息
【发布时间】:2018-11-28 02:10:57
【问题描述】:

我遇到的问题实际上甚至可以在此处的官方 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);

现在这个表达式不匹配一个空字符串。然而,我在验证时没有收到任何错误。

如何在表单中显示空必需值的错误?

【问题讨论】:

    标签: java gwt smartgwt


    【解决方案1】:

    您可以直接使用 setError 方法。并返回表单。

    if(codeField.getText().trim().isEmpty()){
    codeField.setError("The Code must not be Empty.");
    return;
    }
    

    这将返回表单并验证空字符串。

    【讨论】:

    • 是的,我可以这样做,但是当我有验证器时必须手动验证值似乎很愚蠢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-04-24
    • 1970-01-01
    • 1970-01-01
    • 2019-06-11
    • 2016-08-08
    • 2015-04-17
    • 1970-01-01
    相关资源
    最近更新 更多