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 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. ---
  2. title: FormLayout
  3. order: 5
  4. layout: page
  5. ---
  6. [[layout.formlayout]]
  7. = [classname]#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. <<dummy/../../../framework/layout/layout-orderedlayout#layout.orderedlayout,"VerticalLayout
  19. and HorizontalLayout">>.
  20. The following example shows typical use of [classname]#FormLayout# in a form:
  21. [source, java]
  22. ----
  23. FormLayout form = new FormLayout();
  24. TextField tf1 = new TextField("Name");
  25. tf1.setIcon(FontAwesome.USER);
  26. tf1.setRequired(true);
  27. tf1.addValidator(new NullValidator("Must be given", false));
  28. form.addComponent(tf1);
  29. TextField tf2 = new TextField("Street address");
  30. tf2.setIcon(FontAwesome.ROAD);
  31. form.addComponent(tf2);
  32. TextField tf3 = new TextField("Postal code");
  33. tf3.setIcon(FontAwesome.ENVELOPE);
  34. tf3.addValidator(new IntegerRangeValidator("Doh!", 1, 99999));
  35. form.addComponent(tf3);
  36. ----
  37. The resulting layout will look as follows. The error message shows in a tooptip
  38. when you hover the mouse pointer over the error indicator.
  39. [[figure.layout.formlayout]]
  40. .A [classname]#FormLayout# Layout for Forms
  41. image::img/formlayout-example1.png[]
  42. [[layout.formlayout.css]]
  43. == CSS Style Rules
  44. [source, css]
  45. ----
  46. .v-formlayout {}
  47. .v-formlayout .v-caption {}
  48. /* Columns in a field row. */
  49. .v-formlayout-contentcell {} /* Field content. */
  50. .v-formlayout-captioncell {} /* Field caption. */
  51. .v-formlayout-errorcell {} /* Field error indicator. */
  52. /* Overall style of field rows. */
  53. .v-formlayout-row {}
  54. .v-formlayout-firstrow {}
  55. .v-formlayout-lastrow {}
  56. /* Required field indicator. */
  57. .v-formlayout .v-required-field-indicator {}
  58. .v-formlayout-captioncell .v-caption
  59. .v-required-field-indicator {}
  60. /* Error indicator. */
  61. .v-formlayout-cell .v-errorindicator {}
  62. .v-formlayout-error-indicator .v-errorindicator {}
  63. ----
  64. The top-level element of [classname]#FormLayout# has the
  65. [literal]#++v-formlayout++# style. The layout is tabular with three columns: the
  66. caption column, the error indicator column, and the field column. These can be
  67. styled with [literal]#++v-formlayout-captioncell++#,
  68. [literal]#++v-formlayout-errorcell++#, and
  69. [literal]#++v-formlayout-contentcell++#, respectively. While the error indicator
  70. is shown as a dedicated column, the indicator for required fields is currently
  71. shown as a part of the caption column.
  72. For information on setting margins and spacing, see also
  73. <<dummy/../../../framework/layout/layout-orderedlayout#layout.orderedlayout.spacing,"Spacing
  74. in Ordered Layouts">> and
  75. <<dummy/../../../framework/layout/layout-settings#layout.settings.margins,"Layout
  76. Margins">>.