Reputation: 75
I have a simple form that performs validation of each field. For some reason, I think related to the CodenameOne theme, I do not get a red outline or background for fields failing validation, and I do not see the error messages. The form will gray out the "Submit" button until all validations pass, so this part is working. I just can't see the errors on the screen. I have included my form code below. Is this happening because the default theme I am using does not have the required UUIDs to display the error styles?
Is there a way to debug when styles are being applied but are not available in the theme?
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();
Upvotes: 2
Views: 149
Reputation: 52770
The error mode sets the UIID to existing UIID with the word "Invalid" appended to it. So a TextField
will become TextFieldInvalid
.
In the simulator open the Component Inspector tool and traverse the components to see the UIID's that they have. This will allow you to customize the right UIID's in selected/unselected states.
To enable error message display use setShowErrorMessageForFocusedComponent(true)
.
Upvotes: 1