form-helpers.mdx 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 class="form-help" data-bs-toggle="popover" data-bs-placement="top" data-bs-html="true" data-bs-content="<p>...</p>">?</span>
  10. ```
  11. Look at the example below to see how the input help works:
  12. ```html example centered height="25rem" columns={1}
  13. <div>
  14. <label class="form-label">
  15. ZIP Code
  16. <span class="form-help" data-bs-toggle="popover" data-bs-placement="top" data-bs-html="true" 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>">?</span>
  17. </label>
  18. <input type="text" class="form-control" placeholder="Your ZIP Code">
  19. </div>
  20. ```
  21. ## Required field
  22. Use the `.required` class to indicate that a field is required. It will add a red asterisk to the label.
  23. ```html
  24. <label class="form-label required">Required</label>
  25. ```
  26. Look at the example below to see how the required field works:
  27. ```html example centered columns={1}
  28. <div>
  29. <label class="form-label required">Required</label>
  30. <input type="text" class="form-control" name="..." placeholder="Required...">
  31. </div>
  32. ```
  33. ## Form hint
  34. 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.
  35. ```html
  36. <div class="form-hint">We'll never share your email with anyone else.</div>
  37. ```
  38. Look at the example below to see how the form hint works:
  39. ```html example centered columns={1}
  40. <div>
  41. <label class="form-label">Email address</label>
  42. <input type="email" class="form-control" placeholder="Enter your email address">
  43. <div class="form-hint">We'll never share your email with anyone else.</div>
  44. </div>
  45. ```
  46. ## Additional info inside label
  47. 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.
  48. ```html
  49. <label class="form-label">Textarea <span class="form-label-description">56/100</span>
  50. </label>
  51. ```
  52. This example shows how to use the additional info inside the label:
  53. ```html example centered columns={1} height="15rem"
  54. <div>
  55. <label class="form-label">Textarea <span class="form-label-description">56/100</span>
  56. </label>
  57. <textarea class="form-control" name="" rows="3" placeholder="Content.."></textarea>
  58. </div>
  59. ```