event.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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. <!-- form: -->
  15. <section>
  16. <div class="col-lg-8 col-lg-offset-2">
  17. <div class="page-header">
  18. <h2>Sign up</h2>
  19. </div>
  20. <form id="defaultForm" method="post" class="form-horizontal" action="target.php">
  21. <div class="form-group">
  22. <label class="col-lg-3 control-label">Full name</label>
  23. <div class="col-lg-4">
  24. <input type="text" class="form-control" name="firstName" placeholder="First name" />
  25. </div>
  26. <div class="col-lg-4">
  27. <input type="text" class="form-control" name="lastName" placeholder="Last name" />
  28. </div>
  29. </div>
  30. <div class="form-group">
  31. <label class="col-lg-3 control-label">Username</label>
  32. <div class="col-lg-5">
  33. <input type="text" class="form-control" name="username" />
  34. </div>
  35. </div>
  36. <div class="form-group">
  37. <label class="col-lg-3 control-label">Email address</label>
  38. <div class="col-lg-5">
  39. <input type="text" class="form-control" name="email" />
  40. </div>
  41. </div>
  42. <div class="form-group">
  43. <label class="col-lg-3 control-label">Password</label>
  44. <div class="col-lg-5">
  45. <input type="password" class="form-control" name="password" />
  46. </div>
  47. </div>
  48. <div class="form-group">
  49. <label class="col-lg-3 control-label">Retype password</label>
  50. <div class="col-lg-5">
  51. <input type="password" class="form-control" name="confirmPassword" />
  52. </div>
  53. </div>
  54. <div class="form-group">
  55. <label class="col-lg-3 control-label">Gender</label>
  56. <div class="col-lg-5">
  57. <div class="radio">
  58. <label>
  59. <input type="radio" name="gender" value="male" /> Male
  60. </label>
  61. </div>
  62. <div class="radio">
  63. <label>
  64. <input type="radio" name="gender" value="female" /> Female
  65. </label>
  66. </div>
  67. <div class="radio">
  68. <label>
  69. <input type="radio" name="gender" value="other" /> Other
  70. </label>
  71. </div>
  72. </div>
  73. </div>
  74. <div class="form-group">
  75. <label class="col-lg-3 control-label">Languages</label>
  76. <div class="col-lg-5">
  77. <div class="checkbox">
  78. <label>
  79. <input type="checkbox" name="languages[]" value="english" /> English
  80. </label>
  81. </div>
  82. <div class="checkbox">
  83. <label>
  84. <input type="checkbox" name="languages[]" value="french" /> French
  85. </label>
  86. </div>
  87. <div class="checkbox">
  88. <label>
  89. <input type="checkbox" name="languages[]" value="german" /> German
  90. </label>
  91. </div>
  92. <div class="checkbox">
  93. <label>
  94. <input type="checkbox" name="languages[]" value="russian" /> Russian
  95. </label>
  96. </div>
  97. <div class="checkbox">
  98. <label>
  99. <input type="checkbox" name="languages[]" value="other" /> Other
  100. </label>
  101. </div>
  102. </div>
  103. </div>
  104. <div class="form-group">
  105. <label class="col-lg-3 control-label">Programming Languages</label>
  106. <div class="col-lg-5">
  107. <div class="checkbox">
  108. <label>
  109. <input type="checkbox" name="programs[]" value="net" /> .Net
  110. </label>
  111. </div>
  112. <div class="checkbox">
  113. <label>
  114. <input type="checkbox" name="programs[]" value="java" /> Java
  115. </label>
  116. </div>
  117. <div class="checkbox">
  118. <label>
  119. <input type="checkbox" name="programs[]" value="c" /> C/C++
  120. </label>
  121. </div>
  122. <div class="checkbox">
  123. <label>
  124. <input type="checkbox" name="programs[]" value="php" /> PHP
  125. </label>
  126. </div>
  127. <div class="checkbox">
  128. <label>
  129. <input type="checkbox" name="programs[]" value="perl" /> Perl
  130. </label>
  131. </div>
  132. <div class="checkbox">
  133. <label>
  134. <input type="checkbox" name="programs[]" value="ruby" /> Ruby
  135. </label>
  136. </div>
  137. <div class="checkbox">
  138. <label>
  139. <input type="checkbox" name="programs[]" value="python" /> Python
  140. </label>
  141. </div>
  142. <div class="checkbox">
  143. <label>
  144. <input type="checkbox" name="programs[]" value="javascript" /> Javascript
  145. </label>
  146. </div>
  147. </div>
  148. </div>
  149. <div class="form-group">
  150. <div class="col-lg-9 col-lg-offset-3">
  151. <button type="submit" class="btn btn-primary">Sign up</button>
  152. <button type="button" class="btn btn-info" id="validateBtn">Manual validate</button>
  153. </div>
  154. </div>
  155. </form>
  156. </div>
  157. </section>
  158. <!-- :form -->
  159. </div>
  160. </div>
  161. <script type="text/javascript">
  162. $(document).ready(function() {
  163. $('#defaultForm')
  164. .bootstrapValidator({
  165. message: 'This value is not valid',
  166. feedbackIcons: {
  167. valid: 'glyphicon glyphicon-ok',
  168. invalid: 'glyphicon glyphicon-remove',
  169. validating: 'glyphicon glyphicon-refresh'
  170. },
  171. fields: {
  172. firstName: {
  173. validators: {
  174. notEmpty: {
  175. message: 'The first name is required and cannot be empty'
  176. }
  177. }
  178. },
  179. lastName: {
  180. validators: {
  181. notEmpty: {
  182. message: 'The last name is required and cannot be empty'
  183. }
  184. }
  185. },
  186. username: {
  187. message: 'The username is not valid',
  188. validators: {
  189. notEmpty: {
  190. message: 'The username is required and cannot be empty'
  191. },
  192. stringLength: {
  193. min: 6,
  194. max: 30,
  195. message: 'The username must be more than 6 and less than 30 characters long'
  196. },
  197. regexp: {
  198. regexp: /^[a-zA-Z0-9_\.]+$/,
  199. message: 'The username can only consist of alphabetical, number, dot and underscore'
  200. },
  201. // remote: {
  202. // url: 'remote.php',
  203. // message: 'The username is not available'
  204. // },
  205. different: {
  206. field: 'password',
  207. message: 'The username and password cannot be the same as each other'
  208. }
  209. }
  210. },
  211. email: {
  212. validators: {
  213. emailAddress: {
  214. message: 'The input is not a valid email address'
  215. }
  216. }
  217. },
  218. password: {
  219. validators: {
  220. notEmpty: {
  221. message: 'The password is required and cannot be empty'
  222. },
  223. identical: {
  224. field: 'confirmPassword',
  225. message: 'The password and its confirm are not the same'
  226. },
  227. different: {
  228. field: 'username',
  229. message: 'The password cannot be the same as username'
  230. }
  231. }
  232. },
  233. confirmPassword: {
  234. validators: {
  235. notEmpty: {
  236. message: 'The confirm password is required and cannot be empty'
  237. },
  238. identical: {
  239. field: 'password',
  240. message: 'The password and its confirm are not the same'
  241. },
  242. different: {
  243. field: 'username',
  244. message: 'The password cannot be the same as username'
  245. }
  246. }
  247. },
  248. gender: {
  249. validators: {
  250. notEmpty: {
  251. message: 'The gender is required'
  252. }
  253. }
  254. },
  255. 'languages[]': {
  256. validators: {
  257. notEmpty: {
  258. message: 'Please specify at least one language you can speak'
  259. }
  260. }
  261. },
  262. 'programs[]': {
  263. validators: {
  264. choice: {
  265. min: 2,
  266. max: 4,
  267. message: 'Please choose 2 - 4 programming languages you are good at'
  268. }
  269. }
  270. }
  271. }
  272. })
  273. .on('error.form.bv', function(e) {
  274. console.log('error.form.bv');
  275. // You can get the form instance and then access API
  276. var $form = $(e.target);
  277. console.log($form.data('bootstrapValidator').getInvalidFields());
  278. // If you want to prevent the default handler (bootstrapValidator._onError(e))
  279. // e.preventDefault();
  280. })
  281. .on('success.form.bv', function(e) {
  282. console.log('success.form.bv');
  283. // If you want to prevent the default handler (bootstrapValidator._onSuccess(e))
  284. // e.preventDefault();
  285. })
  286. .on('error.field.bv', function(e, data) {
  287. console.log('error.field.bv -->', data);
  288. })
  289. .on('success.field.bv', function(e, data) {
  290. console.log('success.field.bv -->', data);
  291. })
  292. .on('status.field.bv', function(e, data) {
  293. // I don't want to add has-success class to valid field container
  294. data.element.parents('.form-group').removeClass('has-success');
  295. // I want to enable the submit button all the time
  296. data.bv.disableSubmitButtons(false);
  297. });
  298. // Validate the form manually
  299. $('#validateBtn').click(function() {
  300. $('#defaultForm').bootstrapValidator('validate');
  301. });
  302. });
  303. </script>
  304. </body>
  305. </html>