【发布时间】: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