reset.html 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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.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>Reset form example</h2>
  17. </div>
  18. <form id="defaultForm" method="post" class="form-horizontal" action="target.php">
  19. <div class="form-group">
  20. <label class="col-lg-3 control-label">Full name</label>
  21. <div class="col-lg-4">
  22. <input type="text" class="form-control" name="firstName" placeholder="First name" />
  23. </div>
  24. <div class="col-lg-4">
  25. <input type="text" class="form-control" name="lastName" placeholder="Last name" />
  26. </div>
  27. </div>
  28. <div class="form-group">
  29. <label class="col-lg-3 control-label">Email address</label>
  30. <div class="col-lg-5">
  31. <input type="text" class="form-control" name="email" />
  32. </div>
  33. </div>
  34. <div class="form-group">
  35. <label class="col-lg-3 control-label">Gender</label>
  36. <div class="col-lg-5">
  37. <div class="radio">
  38. <label>
  39. <input type="radio" name="gender" value="male" /> Male
  40. </label>
  41. </div>
  42. <div class="radio">
  43. <label>
  44. <input type="radio" name="gender" value="female" /> Female
  45. </label>
  46. </div>
  47. <div class="radio">
  48. <label>
  49. <input type="radio" name="gender" value="other" /> Other
  50. </label>
  51. </div>
  52. </div>
  53. </div>
  54. <div class="form-group">
  55. <div class="col-lg-9 col-lg-offset-3">
  56. <button type="submit" class="btn btn-primary">Join Us</button>
  57. </div>
  58. </div>
  59. </form>
  60. </div>
  61. </div>
  62. </div>
  63. <!-- The modal -->
  64. <div class="modal fade" id="helloModal">
  65. <div class="modal-dialog">
  66. <div class="modal-content">
  67. <div class="modal-header">
  68. <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
  69. <h4 class="modal-title">Hello</h4>
  70. </div>
  71. <div class="modal-body">
  72. <div class="text-center welcome"></div>
  73. </div>
  74. </div>
  75. </div>
  76. </div>
  77. <script type="text/javascript">
  78. $(document).ready(function() {
  79. $('#defaultForm')
  80. .bootstrapValidator({
  81. feedbackIcons: {
  82. valid: 'glyphicon glyphicon-ok',
  83. invalid: 'glyphicon glyphicon-remove',
  84. validating: 'glyphicon glyphicon-refresh'
  85. },
  86. fields: {
  87. firstName: {
  88. validators: {
  89. notEmpty: {
  90. message: 'The first name is required and cannot be empty'
  91. }
  92. }
  93. },
  94. lastName: {
  95. validators: {
  96. notEmpty: {
  97. message: 'The last name is required and cannot be empty'
  98. }
  99. }
  100. },
  101. email: {
  102. validators: {
  103. notEmpty: {
  104. message: 'The email address is required and cannot be empty'
  105. },
  106. emailAddress: {
  107. message: 'The input is not a valid email address'
  108. }
  109. }
  110. },
  111. gender: {
  112. validators: {
  113. notEmpty: {
  114. message: 'The gender is required'
  115. }
  116. }
  117. }
  118. }
  119. })
  120. .on('success.form.bv', function(e) {
  121. // Prevent submit form
  122. e.preventDefault();
  123. var $form = $(e.target),
  124. validator = $form.data('bootstrapValidator');
  125. // Show the modal
  126. var fullName = [validator.getFieldElements('firstName').val(),
  127. validator.getFieldElements('lastName').val()].join(' ');
  128. $('#helloModal')
  129. .find('.welcome').html('Hello ' + fullName).end()
  130. .modal('show');
  131. $form
  132. .bootstrapValidator('disableSubmitButtons', false) // Enable the submit buttons
  133. .bootstrapValidator('resetForm', true); // Reset the form
  134. });
  135. });
  136. </script>
  137. </body>
  138. </html>