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

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