form-validation.mdx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. ---
  2. title: Validation states
  3. summary: To inform users whether the entered value is correct or not, use either of the validation states. Thanks to that, users will immediately know which form elements they need to correct and, if the state displays as invalid, why the value is incorrect.
  4. description: Indicate valid or invalid inputs.
  5. ---
  6. ## Validation states
  7. To inform users whether the entered value is correct or not, use either of the validation states. Thanks to that, users will immediately know which form elements they need to correct and, if the state displays as invalid, why the value is incorrect.
  8. To apply the validation state to the form control, use the `.is-valid` and `.is-invalid` classes.
  9. ```html example centered separated columns="1" height="20rem"
  10. <input type="text" class="form-control is-valid" placeholder="Valid State..." />
  11. <input type="text" class="form-control is-invalid" placeholder="Invalid State..." />
  12. ```
  13. ## Validation feedback
  14. To provide users with additional information about the validation state, you can use the `.valid-feedback` and `.invalid-feedback` classes.
  15. ```html
  16. <input type="text" class="form-control is-valid" placeholder="Valid State..." />
  17. <div class="valid-feedback">Looks good!</div>
  18. ```
  19. This is how it works in the example below:
  20. ```html example centered columns="1" height="20rem"
  21. <div>
  22. <label class="form-label required">City</label>
  23. <input type="text" class="form-control is-invalid" required>
  24. <div class="invalid-feedback">
  25. Please provide a valid city.
  26. </div>
  27. </div>
  28. ```
  29. You can also use the `.valid-feedback` to provide users with positive feedback.
  30. ```html example centered columns="1" height="20rem"
  31. <div>
  32. <label class="form-label required">City</label>
  33. <input type="text" class="form-control is-valid" value="Warsaw">
  34. <div class="valid-feedback">
  35. Looks good!
  36. </div>
  37. </div>
  38. ```
  39. ## Subtle validation states
  40. If you prefer a more subtle manner of informing users of the input control validation state, you can use tick and cross symbols and resign from colored control frames and the validation feedback.
  41. To do this, use the `.is-valid-lite` and `.is-invalid-lite` classes.
  42. ```html
  43. <input type="text" class="form-control is-valid is-valid-lite" placeholder="Valid State..." />
  44. ```
  45. Look how it works in the example below:
  46. ```html example centered separated vertical columns="1" height="20rem"
  47. <input type="text" class="form-control is-valid is-valid-lite" placeholder="Valid State..." />
  48. <input type="text" class="form-control is-invalid is-invalid-lite" placeholder="Invalid State..." />
  49. ```