Codenameone 验证器未突出显示必填字段

Codenameone validator not highlighting required fields

我有一个简单的表单来验证每个字段。出于某种原因,我认为与 CodenameOne 主题相关,我没有看到验证失败的字段的红色轮廓或背景,也没有看到错误消息。在所有验证通过之前,表单将使 "Submit" 按钮变灰,因此这部分工作正常。我只是看不到屏幕上的错误。我在下面包含了我的表单代码。发生这种情况是因为我使用的默认主题没有显示错误样式所需的 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();

错误模式将 UIID 设置为现有 UIID,并附加 "Invalid" 字样。所以 TextField 会变成 TextFieldInvalid

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

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