Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

MarkRequiredFieldsAsSuch.asciidoc 1.5KB

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