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.

ChooseInputFieldComponentsWisely.asciidoc 3.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. ---
  2. title: Choose Input Field Components Wisely
  3. order: 31
  4. layout: page
  5. ---
  6. [[choosing-input-field-components-wisely]]
  7. Choosing input field components wisely
  8. --------------------------------------
  9. The core Vaadin framework has more than ten different input field
  10. components. Choosing the right one can improve your application’s
  11. usability significantly. Which component is the best fit in a certain
  12. situation depends on so many factors that it’s pretty much impossible to
  13. set down any specific rules. Nevertheless, here are some helpful
  14. pointers that might guide you in the right direction.
  15. [[textfield-or-selection-component]]
  16. Textfield or selection component?
  17. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  18. **TextField**s are of course the most obvious choice in most cases.
  19. However, their inherent lack of restrictions requires that the user
  20. understands what kind of values are acceptable. They don't present any
  21. options to choose from, and, although you can restrict them to certain
  22. kinds of values e.g. by using **Converter**s, these restrictions are not
  23. immediately obvious to the user. Furthermore, if the UI in question is
  24. mostly mouse-operated, a *TextField* forces the user to move her hands
  25. to the keyboard to enter a value. Thus, a selection component can in
  26. many cases be more convenient for your users.
  27. [[optiongroup-and-checkbox]]
  28. OptionGroup and Checkbox
  29. ^^^^^^^^^^^^^^^^^^^^^^^^
  30. **OptionGroup**s are handy for very small sets of options (typically
  31. 2-4). You can toggle between single-select (radiobuttons) and
  32. multi-select (checkboxes) with the *setMultiSelect(boolean)* method.
  33. Using an OptionGroups to present purely numerical options might be
  34. somewhat strange, though.
  35. image:img/optiongroup.png[OptionGroup]
  36. For binary either/or, yes/no options, a *CheckBox* is a natural choice.
  37. However, if the meaning of the "no" option (i.e. unchecked) is not
  38. completely obvious, or the "yes" (i.e. checked) option could be
  39. confusing by itself, a two-item single-select *OptionGroup* might be
  40. better, since it clearly states what both options represent.
  41. image:img/checkbox-vs-og.png[Checkbox vs OptionGroup]
  42. [[nativeselect]]
  43. NativeSelect
  44. ^^^^^^^^^^^^
  45. The often-overlooked *NativeSelect* component is also convenient for
  46. small sets of options (up to 10 or so), and works great both for named
  47. items and small sets of numbers.
  48. image:img/nativeselect.png[NativeSelect]
  49. [[combobox]]
  50. ComboBox
  51. ^^^^^^^^
  52. If the set of options is larger than about 10 items, a *ComboBox* might
  53. be a better choice, since it allows the user to search for a specific
  54. value to typing part of it, and supports lazy loading.
  55. image:img/combo.png[ComboBox]
  56. [[slider]]
  57. Slider
  58. ^^^^^^
  59. The *Slider* is great for _quickly_ selecting a value from a wide range
  60. of values, _if precision is not that important_, such as audio volume,
  61. brightness, or any approximate value. (If precision is important it's
  62. much better to allow the user to manually enter the value, such as with
  63. a *TextField*.)
  64. image:img/slider.png[Slider]
  65. [[datefields]]
  66. DateFields
  67. ^^^^^^^^^^
  68. The *PopupDateField* component, which opens a calendar popup for date
  69. selection, is great for entering dates and times. Remember to set the
  70. datefield's _resolution_ to something appropriate: seconds are hardly
  71. relevant in most cases, and sometimes all you need is the date.
  72. image:img/datefield.png[DateField]
  73. There’s also the *InlineDateField*, which is really just the
  74. *PopupDateField*’s datepicker without a textfield. It’s probably a bit
  75. too big to use in most forms, but if picking dates is one of the few
  76. tasks in a form, give it a try if you have the space.