event.html 14 KB

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