PageRenderTime 28ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/demo/event.html

https://gitlab.com/x33n/formvalidation
HTML | 310 lines | 292 code | 16 blank | 2 comment | 0 complexity | fb1e8e665fc947524f7b8c6e2cd8737a MD5 | raw file
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>FormValidation demo</title>
  5. <link rel="stylesheet" href="../vendor/bootstrap/css/bootstrap.css"/>
  6. <link rel="stylesheet" href="../dist/css/formValidation.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/formValidation.js"></script>
  10. <script type="text/javascript" src="../dist/js/framework/bootstrap.js"></script>
  11. </head>
  12. <body>
  13. <div class="container">
  14. <div class="row">
  15. <!-- form: -->
  16. <section>
  17. <div class="col-lg-8 col-lg-offset-2">
  18. <div class="page-header">
  19. <h2>Sign up</h2>
  20. </div>
  21. <form id="defaultForm" method="post" class="form-horizontal" action="target.php">
  22. <div class="form-group">
  23. <label class="col-lg-3 control-label">Full name</label>
  24. <div class="col-lg-4">
  25. <input type="text" class="form-control" name="firstName" placeholder="First name" />
  26. </div>
  27. <div class="col-lg-4">
  28. <input type="text" class="form-control" name="lastName" placeholder="Last name" />
  29. </div>
  30. </div>
  31. <div class="form-group">
  32. <label class="col-lg-3 control-label">Username</label>
  33. <div class="col-lg-5">
  34. <input type="text" class="form-control" name="username" />
  35. </div>
  36. </div>
  37. <div class="form-group">
  38. <label class="col-lg-3 control-label">Email address</label>
  39. <div class="col-lg-5">
  40. <input type="text" class="form-control" name="email" />
  41. </div>
  42. </div>
  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. <div class="form-group">
  151. <div class="col-lg-9 col-lg-offset-3">
  152. <button type="submit" class="btn btn-primary">Sign up</button>
  153. <button type="button" class="btn btn-info" id="validateBtn">Manual validate</button>
  154. </div>
  155. </div>
  156. </form>
  157. </div>
  158. </section>
  159. <!-- :form -->
  160. </div>
  161. </div>
  162. <script type="text/javascript">
  163. $(document).ready(function() {
  164. $('#defaultForm')
  165. .formValidation({
  166. message: 'This value is not valid',
  167. icon: {
  168. valid: 'glyphicon glyphicon-ok',
  169. invalid: 'glyphicon glyphicon-remove',
  170. validating: 'glyphicon glyphicon-refresh'
  171. },
  172. fields: {
  173. firstName: {
  174. validators: {
  175. notEmpty: {
  176. message: 'The first name is required and cannot be empty'
  177. }
  178. }
  179. },
  180. lastName: {
  181. validators: {
  182. notEmpty: {
  183. message: 'The last name is required and cannot be empty'
  184. }
  185. }
  186. },
  187. username: {
  188. message: 'The username is not valid',
  189. validators: {
  190. notEmpty: {
  191. message: 'The username is required and cannot be empty'
  192. },
  193. stringLength: {
  194. min: 6,
  195. max: 30,
  196. message: 'The username must be more than 6 and less than 30 characters long'
  197. },
  198. regexp: {
  199. regexp: /^[a-zA-Z0-9_\.]+$/,
  200. message: 'The username can only consist of alphabetical, number, dot and underscore'
  201. },
  202. // remote: {
  203. // url: 'remote.php',
  204. // message: 'The username is not available'
  205. // }
  206. }
  207. },
  208. email: {
  209. validators: {
  210. emailAddress: {
  211. message: 'The input is not a valid email address'
  212. }
  213. }
  214. },
  215. password: {
  216. validators: {
  217. notEmpty: {
  218. message: 'The password is required and cannot be empty'
  219. },
  220. different: {
  221. field: 'username',
  222. message: 'The password cannot be the same as username'
  223. }
  224. }
  225. },
  226. confirmPassword: {
  227. validators: {
  228. notEmpty: {
  229. message: 'The confirm password is required and cannot be empty'
  230. },
  231. identical: {
  232. field: 'password',
  233. message: 'The password and its confirm are not the same'
  234. }
  235. }
  236. },
  237. gender: {
  238. validators: {
  239. notEmpty: {
  240. message: 'The gender is required'
  241. }
  242. }
  243. },
  244. 'languages[]': {
  245. validators: {
  246. notEmpty: {
  247. message: 'Please specify at least one language you can speak'
  248. }
  249. }
  250. },
  251. 'programs[]': {
  252. validators: {
  253. choice: {
  254. min: 2,
  255. max: 4,
  256. message: 'Please choose 2 - 4 programming languages you are good at'
  257. }
  258. }
  259. }
  260. }
  261. })
  262. .on('err.form.fv', function(e) {
  263. console.log('err.form.fv');
  264. // You can get the form instance and then access API
  265. var $form = $(e.target);
  266. console.log($form.data('formValidation').getInvalidFields());
  267. // If you want to prevent the default handler (formValidation._onError(e))
  268. // e.preventDefault();
  269. })
  270. .on('success.form.fv', function(e) {
  271. console.log('success.form.fv');
  272. // If you want to prevent the default handler (formValidation._onSuccess(e))
  273. // e.preventDefault();
  274. })
  275. .on('err.field.fv', function(e, data) {
  276. console.log('err.field.fv -->', data);
  277. })
  278. .on('success.field.fv', function(e, data) {
  279. console.log('success.field.fv -->', data);
  280. })
  281. .on('status.field.fv', function(e, data) {
  282. // I don't want to add has-success class to valid field container
  283. data.element.parents('.form-group').removeClass('has-success');
  284. // I want to enable the submit button all the time
  285. data.fv.disableSubmitButtons(false);
  286. });
  287. // Validate the form manually
  288. $('#validateBtn').click(function() {
  289. $('#defaultForm').formValidation('validate');
  290. });
  291. });
  292. </script>
  293. </body>
  294. </html>