collapse.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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>Using with Bootstrap Collapse</h2>
  17. </div>
  18. <form id="defaultForm" method="post" class="form-horizontal" action="target.php">
  19. <div class="panel-group" id="steps">
  20. <!-- Step 1 -->
  21. <div class="panel panel-default">
  22. <div class="panel-heading">
  23. <h4 class="panel-title"><a data-toggle="collapse" data-parent="#steps" href="#stepOne">Account</a></h4>
  24. </div>
  25. <div id="stepOne" class="panel-collapse collapse in">
  26. <div class="panel-body">
  27. <div class="form-group">
  28. <label class="col-lg-3 control-label">Username</label>
  29. <div class="col-lg-5">
  30. <input type="text" class="form-control" name="username" />
  31. </div>
  32. </div>
  33. <div class="form-group">
  34. <label class="col-lg-3 control-label">Email address</label>
  35. <div class="col-lg-5">
  36. <input type="text" class="form-control" name="email" />
  37. </div>
  38. </div>
  39. <div class="form-group">
  40. <label class="col-lg-3 control-label">Password</label>
  41. <div class="col-lg-5">
  42. <input type="password" class="form-control" name="password" />
  43. </div>
  44. </div>
  45. </div>
  46. </div>
  47. </div>
  48. <!-- Step 2 -->
  49. <div class="panel panel-default">
  50. <div class="panel-heading">
  51. <h4 class="panel-title"><a data-toggle="collapse" data-parent="#steps" href="#stepTwo">Personal</a></h4>
  52. </div>
  53. <div id="stepTwo" class="panel-collapse collapse">
  54. <div class="panel-body">
  55. <div class="form-group">
  56. <label class="col-lg-3 control-label">Full name</label>
  57. <div class="col-lg-4">
  58. <input type="text" class="form-control" name="firstName" placeholder="First name" />
  59. </div>
  60. <div class="col-lg-4">
  61. <input type="text" class="form-control" name="lastName" placeholder="Last name" />
  62. </div>
  63. </div>
  64. <div class="form-group">
  65. <label class="col-lg-3 control-label">Gender</label>
  66. <div class="col-lg-5">
  67. <div class="radio">
  68. <label>
  69. <input type="radio" name="gender" value="male" /> Male
  70. </label>
  71. </div>
  72. <div class="radio">
  73. <label>
  74. <input type="radio" name="gender" value="female" /> Female
  75. </label>
  76. </div>
  77. <div class="radio">
  78. <label>
  79. <input type="radio" name="gender" value="other" /> Other
  80. </label>
  81. </div>
  82. </div>
  83. </div>
  84. <div class="form-group">
  85. <label class="col-lg-3 control-label">Birthday</label>
  86. <div class="col-lg-5">
  87. <input type="text" class="form-control" name="birthday" placeholder="YYYY/MM/DD" />
  88. </div>
  89. </div>
  90. <div class="form-group">
  91. <label class="col-lg-3 control-label">Bio</label>
  92. <div class="col-lg-5">
  93. <textarea class="form-control" name="bio" rows="5"></textarea>
  94. </div>
  95. </div>
  96. </div>
  97. </div>
  98. </div>
  99. <!-- Step 3 -->
  100. <div class="panel panel-default">
  101. <div class="panel-heading">
  102. <h4 class="panel-title"><a data-toggle="collapse" data-parent="#steps" href="#stepThree">Contact</a></h4>
  103. </div>
  104. <div id="stepThree" class="panel-collapse collapse">
  105. <div class="panel-body">
  106. <div class="form-group">
  107. <label class="col-lg-3 control-label">Phone number</label>
  108. <div class="col-lg-5">
  109. <input type="text" class="form-control" name="phoneNumber" />
  110. </div>
  111. </div>
  112. <div class="form-group">
  113. <label class="col-lg-3 control-label">Street</label>
  114. <div class="col-lg-5">
  115. <input type="text" class="form-control" name="street" />
  116. </div>
  117. </div>
  118. <div class="form-group">
  119. <label class="col-lg-3 control-label">City</label>
  120. <div class="col-lg-5">
  121. <input type="text" class="form-control" name="city" />
  122. </div>
  123. </div>
  124. <div class="form-group">
  125. <div class="col-lg-9 col-lg-offset-3">
  126. <button type="submit" class="btn btn-primary" name="signup" value="Sign up">Sign up</button>
  127. </div>
  128. </div>
  129. </div>
  130. </div>
  131. </div>
  132. </div>
  133. </form>
  134. </div>
  135. </div>
  136. </div>
  137. <script type="text/javascript">
  138. $(document).ready(function() {
  139. $('#defaultForm').bootstrapValidator({
  140. message: 'This value is not valid',
  141. excluded: ':disabled',
  142. feedbackIcons: {
  143. valid: 'glyphicon glyphicon-ok',
  144. invalid: 'glyphicon glyphicon-remove',
  145. validating: 'glyphicon glyphicon-refresh'
  146. },
  147. fields: {
  148. firstName: {
  149. validators: {
  150. notEmpty: {
  151. message: 'The first name is required and cannot be empty'
  152. },
  153. stringCase: {
  154. message: 'The first name must contain upper case characters only',
  155. case: 'upper'
  156. },
  157. regexp: {
  158. regexp: /^[A-Z\s]+$/i,
  159. message: 'The first name can only consist of alphabetical characters and spaces'
  160. }
  161. }
  162. },
  163. lastName: {
  164. validators: {
  165. notEmpty: {
  166. message: 'The last name is required and cannot be empty'
  167. },
  168. stringCase: {
  169. message: 'The last name must contain upper case characters only',
  170. case: 'upper'
  171. },
  172. regexp: {
  173. regexp: /^[A-Z\s]+$/i,
  174. message: 'The last name can only consist of alphabetical characters and spaces'
  175. }
  176. }
  177. },
  178. username: {
  179. message: 'The username is not valid',
  180. validators: {
  181. notEmpty: {
  182. message: 'The username is required and cannot be empty'
  183. },
  184. stringLength: {
  185. min: 6,
  186. max: 30,
  187. message: 'The username must be more than 6 and less than 30 characters long'
  188. },
  189. regexp: {
  190. regexp: /^[a-zA-Z0-9_\.]+$/,
  191. message: 'The username can only consist of alphabetical, number, dot and underscore'
  192. },
  193. different: {
  194. field: 'password',
  195. message: 'The username and password cannot be the same as each other'
  196. }
  197. }
  198. },
  199. email: {
  200. validators: {
  201. emailAddress: {
  202. message: 'The input is not a valid email address'
  203. }
  204. }
  205. },
  206. password: {
  207. validators: {
  208. notEmpty: {
  209. message: 'The password is required and cannot be empty'
  210. },
  211. different: {
  212. field: 'username',
  213. message: 'The password cannot be the same as username'
  214. }
  215. }
  216. },
  217. gender: {
  218. validators: {
  219. notEmpty: {
  220. message: 'The gender is required'
  221. }
  222. }
  223. },
  224. birthday: {
  225. validators: {
  226. date: {
  227. format: 'YYYY/MM/DD',
  228. message: 'The birthday is not valid'
  229. }
  230. }
  231. },
  232. phoneNumber: {
  233. validators: {
  234. digits: {
  235. message: 'The value can contain only digits'
  236. }
  237. }
  238. }
  239. }
  240. }).on('error.form.bv', function(e) {
  241. console.log('error');
  242. // Active the panel element containing the first invalid element
  243. var $form = $(e.target),
  244. validator = $form.data('bootstrapValidator'),
  245. $invalidField = validator.getInvalidFields().eq(0),
  246. $collapse = $invalidField.parents('.collapse');
  247. $collapse.collapse('show');
  248. });
  249. });
  250. </script>
  251. </body>
  252. </html>