【问题标题】:Codenameone validator not highlighting required fieldsCodenameone 验证器未突出显示必填字段
【发布时间】:2016-08-24 12:02:11
【问题描述】:

我有一个简单的表单来执行每个字段的验证。出于某种原因,我认为与 CodenameOne 主题有关,我没有得到验证失败的字段的红色轮廓或背景,并且我没有看到错误消息。在所有验证通过之前,表单将使“提交”按钮变灰,因此这部分工作正常。我只是在屏幕上看不到错误。我在下面包含了我的表单代码。这是因为我使用的默认主题没有显示错误样式所需的 UUID 吗?

当样式被应用但在主题中不可用时,有没有办法调试?

   Form registrationForm = new Form("My Registration");
    BorderLayout bl = new BorderLayout();
    bl.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_CENTER);
    registrationForm.setLayout(bl);
    registrationForm.setFormBottomPaddingEditingMode(true);
    ComponentGroup cg = new ComponentGroup();
    final TextField nicknameField = new TextField("", "Screen name (publicly viewable)", 25, TextArea.ANY);
    cg.addComponent(nicknameField);
    final TextField emailField = new TextField("", "Email address", 40, TextArea.EMAILADDR);
    cg.addComponent(emailField);
    final TextField passwordField = new TextField("", "Password", 40, TextArea.PASSWORD);
    cg.addComponent(passwordField);
    final TextField passwordConfirmField = new TextField("", "Type your password again", 40, TextArea.PASSWORD);
    cg.addComponent(passwordConfirmField);
    final TextField sloganField = new TextField("", "Slogan (publicly viewable), ex: Go Hokies!", 30, TextArea.ANY);
    cg.addComponent(sloganField);

    Button submit = new Button("Submit");
    Validator v = new Validator();

    v.addConstraint(nicknameField, new LengthConstraint(3));
    v.addConstraint(emailField, RegexConstraint.validEmail("You must enter a valid email address to receive confirmation"));
    v.addConstraint(passwordField, new LengthConstraint(8));
    v.addConstraint(passwordConfirmField, new LengthConstraint(8));
    v.addSubmitButtons(submit);
    submit.addActionListener((e) -> {
        String password = passwordField.getText();
        String passwordConfirm = passwordConfirmField.getText();
        if (!password.equals(passwordConfirm)) {
            Dialog.show("Password error", "The password and password confirmation did not match. Please retype them.", "OK", null);
        } else {
            showConfirmation();
        }
    });   
    cg.addComponent(submit);
    registrationForm.addComponent(BorderLayout.CENTER, cg);
    registrationForm.show();

【问题讨论】:

    标签: codenameone


    【解决方案1】:

    错误模式将 UIID 设置为现有 UIID,并附加“无效”一词。所以TextField 将变为TextFieldInvalid。

    在模拟器中打开组件检查器工具并遍历组件以查看它们拥有的 UIID。这将允许您在选定/未选定状态下自定义正确的 UIID。

    要启用错误消息显示,请使用setShowErrorMessageForFocusedComponent(true)。

    【讨论】:

      猜你喜欢
      • 2012-05-11
      • 2013-03-23
      • 2011-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多