enable2.html 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>BootstrapValidator demo</title>
  5. <link rel="stylesheet" href="../vendor/bootstrap/css/bootstrap.css"/>
  6. <link rel="stylesheet" href="../dist/css/bootstrapValidator.css"/>
  7. <script type="text/javascript" src="../vendor/jquery/jquery-1.10.2.min.js"></script>
  8. <script type="text/javascript" src="../vendor/bootstrap/js/bootstrap.min.js"></script>
  9. <script type="text/javascript" src="../dist/js/bootstrapValidator.js"></script>
  10. </head>
  11. <body>
  12. <div class="container">
  13. <div class="row">
  14. <div class="col-lg-8 col-lg-offset-2">
  15. <div class="page-header">
  16. <h2>Enable/disable validator</h2>
  17. </div>
  18. <form id="signupForm" method="post" class="form-horizontal" action="target.php">
  19. <div class="form-group">
  20. <label class="col-md-3 control-label">Full name (*)</label>
  21. <div class="col-md-5">
  22. <input type="text" class="form-control" name="full_name" />
  23. </div>
  24. </div>
  25. <div class="form-group">
  26. <label class="col-md-3 control-label">Password</label>
  27. <div class="col-md-5">
  28. <input type="password" class="form-control" name="password" />
  29. <span class="help-block">Leave it blank if you don't want to change it</span>
  30. </div>
  31. </div>
  32. <div class="form-group">
  33. <label class="col-md-3 control-label">Confirm password</label>
  34. <div class="col-md-5">
  35. <input type="password" class="form-control" name="confirm_password" />
  36. <span class="help-block">Required if the password above is not empty</span>
  37. </div>
  38. </div>
  39. <div class="form-group">
  40. <div class="col-lg-9 col-lg-offset-3">
  41. <button type="submit" class="btn btn-primary">Submit</button>
  42. </div>
  43. </div>
  44. </form>
  45. </div>
  46. </div>
  47. </div>
  48. <script type="text/javascript">
  49. $(document).ready(function() {
  50. $('#signupForm').bootstrapValidator({
  51. message: 'This value is not valid',
  52. feedbackIcons: {
  53. valid: 'glyphicon glyphicon-ok',
  54. invalid: 'glyphicon glyphicon-remove',
  55. validating: 'glyphicon glyphicon-refresh'
  56. },
  57. fields: {
  58. full_name: {
  59. validators: {
  60. notEmpty: {
  61. message: 'The full name is required and cannot be empty'
  62. }
  63. }
  64. },
  65. password: {
  66. enabled: false,
  67. validators: {
  68. notEmpty: {
  69. message: 'The password is required and cannot be empty'
  70. },
  71. identical: {
  72. field: 'confirm_password',
  73. message: 'The password and its confirm must be the same'
  74. }
  75. }
  76. },
  77. confirm_password: {
  78. enabled: false,
  79. validators: {
  80. notEmpty: {
  81. message: 'The confirm password is required and cannot be empty'
  82. },
  83. identical: {
  84. field: 'password',
  85. message: 'The password and its confirm must be the same'
  86. }
  87. }
  88. }
  89. }
  90. });
  91. // Enable the password/confirm password validators if the password is not empty
  92. $('#signupForm').find('[name="password"]').on('keyup', function() {
  93. var isEmpty = $(this).val() == '';
  94. $('#signupForm').bootstrapValidator('enableFieldValidators', 'password', !isEmpty)
  95. .bootstrapValidator('enableFieldValidators', 'confirm_password', !isEmpty);
  96. });
  97. });
  98. </script>
  99. </body>
  100. </html>