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.

ConfigureInputFieldsToGuideDataEntry.asciidoc 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. ---
  2. title: Configure Input Fields To Guide Data Entry
  3. order: 83
  4. layout: page
  5. ---
  6. [[configure-input-fields-to-guide-data-entry]]
  7. = Configure input fields to guide data entry
  8. [[field-size]]
  9. Field size
  10. ^^^^^^^^^^
  11. There are a number of tricks we can use to help users understand what
  12. kind of values we expect them to enter into a field, without resorting
  13. to tooltips, footnotes or excessively long captions. Consider the form
  14. below:
  15. image:img/form1.png[Basic form]
  16. The shape, size and layout of these fields don’t really correspond to
  17. the kinds of values expected to be entered in them, or to the relations
  18. between different fields. For instance, while the homepage url is
  19. probably between 25 and 55 characters long, European postal codes are
  20. only about 6 digits long, and age maxes out at three digits. By setting
  21. the widths of these fields to be approximately proportional to the
  22. lengths of expected values, the fields become easier to identify, and
  23. the entire form feels more friendly and less monotonous:
  24. image:img/form2.png[Form with different input widths]
  25. Please note that there is no point in trying to _match_ the _exact_
  26. lengths of expected values – the positive effect here relies more on the
  27. sizes of fields _relative to each other_ than on specific widths. Also
  28. note that it’s important not to make the shortest fields too short just
  29. to distinguish them from longer ones. An address field that can only
  30. display 10 characters at a time would be really annoying.
  31. An easy way to set field widths to approximately a certain number of
  32. characters is to set the component’s widths using
  33. http://en.wikipedia.org/wiki/Em_(typography)[Em units], found in
  34. Vaadin’s *Sizeable.Unit* enum. One *Em* is approximately the width of
  35. (actually usually slightly wider than) an uppercase M.
  36. [source,java]
  37. ....
  38. TextField tfPostalCode = new TextField("Postal code");
  39. tfPostalCode.setWidth(6, Unit.EM);
  40. ....
  41. This was all about the _width_ of input fields, since most input fields
  42. are single-line. Fields for which you expect more than a few words of
  43. text should of course be multi-line *TextAreas*. While the height of a
  44. *TextArea* might not be as important as the width of a *TextField*
  45. (since it has scrollbars), it’s still a good idea to set both the width
  46. and the height of a *TextArea* to roughly match the amount of text you
  47. expect people to enter. A bigger *TextArea* encourages the user to enter
  48. more text into it, while a smaller area suggests that perhaps a few
  49. carefully chosen words is enough, thank you very much.
  50. [[component-grouping]]
  51. Component grouping
  52. ^^^^^^^^^^^^^^^^^^
  53. Some of the fields in the above example clearly “belong together”. First
  54. and last name. Street address, postal code, city and country. By
  55. changing the layout slightly, moving the most closely related fields to
  56. the same line and adding a little spacing between groups of related
  57. fields the fields become even easier to identify, and the form easier to
  58. understand in a single glance:
  59. image:img/form3.png[Form with grouped inputs]
  60. (See layout component sections in Tutorial and Book of Vaadin to see how
  61. this is done in Vaadin.)
  62. [[placeholders]]
  63. Placeholders
  64. ^^^^^^^^^^^^
  65. A placeholder is an input prompt text inside an input field that
  66. disappears as soon as a value is entered into the field. Many input
  67. components in Vaadin have a *setPlaceholder()* method for this:
  68. [source,java]
  69. ....
  70. TextField tfSearch = new TextField();
  71. tfSearch.setPlaceholder(“Search by keywords”);
  72. ....
  73. One use for placeholders is as an alternative to a separate *caption*.
  74. This can be useful especially if there is very little space for the
  75. field, or if you wish to reduce the visual clutter of your UI. A common
  76. example is a search or text-filter field with a placeholder like
  77. _“Search by keywords”_ or _“Filter by name”_ :
  78. image:img/searchfield.png[Search field placeholder]
  79. The decision to use placeholders as captions should not be taken
  80. lightly, however. Keep in mind that the placeholder disappears as soon
  81. as any text is entered into the field, so the user will have to remember
  82. what the field was for, or be able to deduce its identity from its
  83. current value. In the example above, with just a single search field, or
  84. even in a login form with username and password fields, this is
  85. acceptable. In a significantly longer form, however, especially one that
  86. the user might wish to read through before submitting to check that
  87. everything has been correctly entered, this approach quickly turns into
  88. a problem.
  89. Another way to use placeholders is for displaying *additional
  90. information* about the field, such as the expected *format*, or the
  91. *types of values that are accepted*. This is quite similar to
  92. *tooltips*, with the difference that the placeholder must be kept short
  93. enough to fit into the field itself, and that it is immediately visible,
  94. without hovering over the field with the mouse pointer. For this reason,
  95. placeholders are useful on touch screens, as opposed to tooltips.
  96. A good example of indicating the types of values a fields accepts is a
  97. _Location_ field where you can enter a street address, a postal code or
  98. just the name of the city. These details are probably too long to fit in
  99. the field’s caption, and might not be discoverable enough in a tooltip.
  100. A placeholder briefly explaining the options is an excellent solution:
  101. image:img/locationfield.png[Input field with placeholder]