form-helpers.mdx 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. ---
  2. title: Form helpers
  3. summary: Use form helpers to provide additional information about a form element. You can use input help, required field, form hint, and additional info inside the label.
  4. description: Provide additional guidance in forms.
  5. ---
  6. ## Input help
  7. Use an input helper to display additional information about a form element. The text label will appear once a user hovers over the helper. To add an input helper, use the `.form-help` class.
  8. ```html
  9. <span
  10. class="form-help"
  11. data-bs-toggle="popover"
  12. data-bs-placement="top"
  13. data-bs-html="true"
  14. data-bs-content="<p>...</p>"
  15. >?</span
  16. >
  17. ```
  18. Look at the example below to see how the input help works:
  19. ```html example centered height="25rem" columns={1}
  20. <div>
  21. <label class="form-label">
  22. ZIP Code
  23. <span
  24. class="form-help"
  25. data-bs-toggle="popover"
  26. data-bs-placement="top"
  27. data-bs-html="true"
  28. data-bs-content="<p>ZIP Code must be US or CDN format. You can use an extended ZIP+4 code to determine address more accurately.</p><p class='mb-0'><a href=''>USP ZIP codes lookup tools</a></p>"
  29. >?</span
  30. >
  31. </label>
  32. <input type="text" class="form-control" placeholder="Your ZIP Code" />
  33. </div>
  34. ```
  35. ## Required field
  36. Use the `.required` class to indicate that a field is required. It will add a red asterisk to the label.
  37. ```html
  38. <label class="form-label required">Required</label>
  39. ```
  40. Look at the example below to see how the required field works:
  41. ```html example centered columns={1}
  42. <div>
  43. <label class="form-label required">Required</label>
  44. <input type="text" class="form-control" name="..." placeholder="Required..." />
  45. </div>
  46. ```
  47. ## Form hint
  48. Use a form hint to provide users with additional information about a form element. The text will appear below the input field. To add a form hint, use the `.form-hint` class.
  49. ```html
  50. <div class="form-hint">We'll never share your email with anyone else.</div>
  51. ```
  52. Look at the example below to see how the form hint works:
  53. ```html example centered columns={1}
  54. <div>
  55. <label class="form-label">Email address</label>
  56. <input type="email" class="form-control" placeholder="Enter your email address" />
  57. <div class="form-hint">We'll never share your email with anyone else.</div>
  58. </div>
  59. ```
  60. ## Additional info inside label
  61. Use the `.form-label-description` class to add additional information to the label. The text will appear next to the label. You can use it to add for example a character counter.
  62. ```html
  63. <label class="form-label">Textarea <span class="form-label-description">56/100</span> </label>
  64. ```
  65. This example shows how to use the additional info inside the label:
  66. ```html example centered columns={1} height="15rem"
  67. <div>
  68. <label class="form-label">Textarea <span class="form-label-description">56/100</span> </label>
  69. <textarea class="form-control" name="" rows="3" placeholder="Content.."></textarea>
  70. </div>
  71. ```