代码之家  ›  专栏  ›  技术社区  ›  TomáÅ¡ Zato

在窗体验证期间,当值为空时也显示错误消息

  •  1
  • TomáÅ¡ Zato  · 技术社区  · 7 年前

    我遇到的问题甚至可以在官方的SmartGWT演示中看到: https://www.smartclient.com/smartgwt/showcase/#form_validation_regexp

    如果输入nothing(将字段留空)并按validate,则不会显示任何错误。对于required值,即使字段为空,也需要显示错误。

    我将验证器设置为:

        RegExpValidator regExpValidator = new RegExpValidator();  
        regExpValidator.setExpression("^[0-9A-Z_]{7,12}$");  
        regExpValidator.setErrorMessage("Code must contain capital letters and numbers");
        codeField.setValidators(regExpValidator);
    

    如何在窗体中显示空必需值的错误?

    1 回复  |  直到 7 年前
        1
  •  1
  •   avish98    7 年前

    可以直接使用setError方法。把表格还给我。

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

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