我有一个简单的表单来执行每个字段的验证。出于某种原因,我认为与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();
答案 0 :(得分:1)
错误模式将UIID设置为现有的UIID,单词为"无效"附加到它。因此TextField
将成为TextFieldInvalid
。
在模拟器中打开Component Inspector工具并遍历组件以查看他们拥有的UIID。这将允许您在选定/未选定状态下自定义正确的UIID。
要启用错误消息显示,请使用setShowErrorMessageForFocusedComponent(true)
。