option-display.html 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Display</title>
  6. <link rel="stylesheet" href="demo.css">
  7. <script src="https://cdn.jsdelivr.net/jquery/1.12.3/jquery.min.js"></script>
  8. <script src="../dist/jquery.validator.js?local=en"></script>
  9. </head>
  10. <body>
  11. <form class="form" data-validator-option="{timely:2}">
  12. <h3>Default behavior</h3>
  13. <p class="note">data-rule="required"</p>
  14. <div class="form-item">
  15. <input type="text" name="name" data-rule="required">
  16. </div>
  17. <div class="form-item">
  18. <button type="submit">Submit</button>
  19. </div>
  20. </form>
  21. <form class="form" data-validator-option="{timely:2}">
  22. <h3>Set the field display by rule string</h3>
  23. <p class="note">data-rule="Name: required"</p>
  24. <div class="form-item">
  25. <input type="text" name="name" data-rule="Name:required">
  26. </div>
  27. <div class="form-item">
  28. <button type="submit">Submit</button>
  29. </div>
  30. </form>
  31. <form class="form" data-validator-option="{timely:2}">
  32. <h3>Set the field display by bind display</h3>
  33. <p class="note">data-rule="required" data-display="Name"</p>
  34. <div class="form-item">
  35. <input type="text" name="name" data-rule="required" data-display="Name">
  36. </div>
  37. <div class="form-item">
  38. <button type="submit">Submit</button>
  39. </div>
  40. </form>
  41. <form class="form" id="form4">
  42. <h3>Dynamic get field display.</h3>
  43. <div class="form-item">
  44. <label class="label">Name</label>
  45. <input type="text" name="name" data-rule="required">
  46. </div>
  47. <div class="form-item">
  48. <button type="submit">Submit</button>
  49. </div>
  50. </form>
  51. <script>
  52. $('#form4').validator({
  53. timely:2,
  54. display: function(el) {
  55. return $(el).closest('.form-item').find('label.label').text();
  56. }
  57. });
  58. </script>
  59. </body>
  60. </html>