You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MarkRequiredFieldsAsSuch.asciidoc 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. ---
  2. title: Mark Required Fields As Such
  3. order: 61
  4. layout: page
  5. ---
  6. [[mark-required-fields-as-such]]
  7. Mark required fields as such
  8. ----------------------------
  9. Don’t make your users guess which fields in your form are required. Mark
  10. them as such:
  11. [source,java]
  12. ....
  13. TextField tfFirstName = new TextField("First name");
  14. tfFirstName.setRequired(true);
  15. tfFirstName.setRequiredError("First name must be filled in!");
  16. ....
  17. Required fields get a small *asterisk* after the caption (or after the
  18. field itself, if it doesn’t have a caption), which is quite universally
  19. understood to mean “required”. Of course, it certainly doesn’t hurt to
  20. have “footnote” somewhere in your form that explains it anyway.
  21. image:img/reqfield.png[Required field with asterisk]
  22. Marking a field as required also implicitly adds a non-empty validator
  23. to the field, preventing the form from being submitted unless a value
  24. has been entered. The error message associated with that validator can
  25. be set with the *setRequiredError()* method:
  26. [source,java]
  27. ....
  28. TextField tfFirstName = new TextField("First name");
  29. tfFirstName.setRequired(true);
  30. tfFirstName.setRequiredError("First name must be filled in!");
  31. ....
  32. image:img/errortooltip.png[Required field with error]
  33. Think carefully about which fields really are required, though. For
  34. instance, asking unnecessary questions in a sign-up form has a tendency
  35. to make people either cancel signing up, or enter nonsense information
  36. in fields they deem nonessential. Only mark as required fields that you
  37. really need the user to fill in, right there and then.