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.

layout-formlayout.asciidoc 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. ---
  2. title: FormLayout
  3. order: 5
  4. layout: page
  5. ---
  6. [[layout.formlayout]]
  7. = FormLayout
  8. ifdef::web[]
  9. [.sampler]
  10. image:{live-demo-image}[alt="Live Demo", link="http://demo.vaadin.com/sampler/#ui/layout/form-layout"]
  11. endif::web[]
  12. [classname]#FormLayout# lays the components and their captions out in two
  13. columns, with optional indicators for required fields and errors that can be
  14. shown for each field. The field captions can have an icon in addition to the
  15. text. [classname]#FormLayout# is an ordered layout and much like
  16. [classname]#VerticalLayout#. For description of margins, spacing, and other
  17. features in ordered layouts, see
  18. <<layout-orderedlayout#layout.orderedlayout, "VerticalLayout and HorizontalLayout">>.
  19. The following example shows typical use of [classname]#FormLayout# in a form:
  20. [source, java]
  21. ----
  22. FormLayout form = new FormLayout();
  23. TextField tf1 = new TextField("Name");
  24. tf1.setIcon(VaadinIcons.USER);
  25. tf1.setRequiredIndicatorVisible(true);
  26. form.addComponent(tf1);
  27. TextField tf2 = new TextField("Street address");
  28. tf2.setIcon(VaadinIcons.ROAD);
  29. form.addComponent(tf2);
  30. TextField tf3 = new TextField("Postal code");
  31. tf3.setIcon(VaadinIcons.ENVELOPE);
  32. form.addComponent(tf3);
  33. // normally comes from validation by Binder
  34. tf3.setComponentError(new UserError("Doh!"));
  35. ----
  36. The resulting layout will look as follows. The error message shows in a tooltip
  37. when you hover the mouse pointer over the error indicator.
  38. [[figure.layout.formlayout]]
  39. .A [classname]#FormLayout# Layout for Forms
  40. image::img/formlayout-example1.png[width=50%, scaledwidth=70%]
  41. [[layout.formlayout.css]]
  42. == CSS Style Rules
  43. [source, css]
  44. ----
  45. .v-formlayout {}
  46. .v-formlayout .v-caption {}
  47. /* Columns in a field row. */
  48. .v-formlayout-contentcell {} /* Field content. */
  49. .v-formlayout-captioncell {} /* Field caption. */
  50. .v-formlayout-errorcell {} /* Field error indicator. */
  51. /* Overall style of field rows. */
  52. .v-formlayout-row {}
  53. .v-formlayout-firstrow {}
  54. .v-formlayout-lastrow {}
  55. /* Required field indicator. */
  56. .v-formlayout .v-required-field-indicator {}
  57. .v-formlayout-captioncell .v-caption
  58. .v-required-field-indicator {}
  59. /* Error indicator. */
  60. .v-formlayout-cell .v-errorindicator {}
  61. .v-formlayout-error-indicator .v-errorindicator {}
  62. ----
  63. The top-level element of [classname]#FormLayout# has the
  64. [literal]#++v-formlayout++# style. The layout is tabular with three columns: the
  65. caption column, the error indicator column, and the field column. These can be
  66. styled with [literal]#++v-formlayout-captioncell++#,
  67. [literal]#++v-formlayout-errorcell++#, and
  68. [literal]#++v-formlayout-contentcell++#, respectively. While the error indicator
  69. is shown as a dedicated column, the indicator for required fields is currently
  70. shown as a part of the caption column.
  71. For information on setting margins and spacing, see also
  72. <<layout-orderedlayout#layout.orderedlayout.spacing,"Spacing
  73. in Ordered Layouts">> and
  74. <<layout-settings#layout.settings.margins, "Layout Margins">>.