You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

191 lines
3.5 KiB

  1. semantic.validateForm = {};
  2. // ready event
  3. semantic.validateForm.ready = function() {
  4. // selector cache
  5. var
  6. $dogForm = $('.dog.example .ui.form'),
  7. $dropdownForm = $('.dropdown.example .ui.form'),
  8. $inlineForm = $('.inline.example .ui.form'),
  9. $form = $('.ui.form').not($dogForm).not($inlineForm).not($dropdownForm),
  10. $checkbox = $('.ui.checkbox'),
  11. $dropdown = $('.ui.dropdown'),
  12. // alias
  13. handler
  14. ;
  15. // event handlers
  16. handler = {
  17. };
  18. $checkbox
  19. .checkbox()
  20. ;
  21. $dropdown
  22. .dropdown()
  23. ;
  24. $.fn.form.settings.defaults = {
  25. firstName: {
  26. identifier : 'first-name',
  27. rules: [
  28. {
  29. type : 'empty',
  30. prompt : 'Please enter your first name'
  31. }
  32. ]
  33. },
  34. name: {
  35. identifier : 'name',
  36. rules: [
  37. {
  38. type : 'empty',
  39. prompt : 'Please enter you name'
  40. }
  41. ]
  42. },
  43. gender: {
  44. identifier : 'gender',
  45. rules: [
  46. {
  47. type : 'empty',
  48. prompt : 'Please select a gender'
  49. }
  50. ]
  51. },
  52. lastName: {
  53. identifier : 'last-name',
  54. rules: [
  55. {
  56. type : 'empty',
  57. prompt : 'Please enter your last name'
  58. }
  59. ]
  60. },
  61. username: {
  62. identifier : 'username',
  63. rules: [
  64. {
  65. type : 'empty',
  66. prompt : 'Please enter a username'
  67. }
  68. ]
  69. },
  70. email: {
  71. identifier : 'email',
  72. rules: [
  73. {
  74. type : 'empty',
  75. prompt : 'Please enter your email'
  76. },
  77. {
  78. type : 'email',
  79. prompt : 'Please enter a valid email'
  80. }
  81. ]
  82. },
  83. password: {
  84. identifier : 'password',
  85. rules: [
  86. {
  87. type : 'empty',
  88. prompt : 'Please enter a password'
  89. },
  90. {
  91. type : 'length[6]',
  92. prompt : 'Your password must be at least 6 characters'
  93. }
  94. ]
  95. },
  96. passwordConfirm: {
  97. identifier : 'password-confirm',
  98. rules: [
  99. {
  100. type : 'empty',
  101. prompt : 'Please confirm your password'
  102. },
  103. {
  104. identifier : 'password-confirm',
  105. type : 'match[password]',
  106. prompt : 'Please verify password matches'
  107. }
  108. ]
  109. },
  110. terms: {
  111. identifier : 'terms',
  112. rules: [
  113. {
  114. type : 'checked',
  115. prompt : 'You must agree to the terms and conditions'
  116. }
  117. ]
  118. }
  119. };
  120. $inlineForm
  121. .form({}, {
  122. inline : true,
  123. on: 'blur'
  124. })
  125. ;
  126. $dropdownForm
  127. .form({
  128. gender: {
  129. identifier : 'gender',
  130. rules: [
  131. {
  132. type : 'empty',
  133. prompt : 'Please enter a gender'
  134. }
  135. ]
  136. },
  137. name: {
  138. identifier : 'name',
  139. rules: [
  140. {
  141. type : 'empty',
  142. prompt : 'Please enter your name'
  143. }
  144. ]
  145. },
  146. })
  147. .find('.dropdown')
  148. .dropdown()
  149. ;
  150. $dogForm
  151. .form({
  152. dog: {
  153. identifier: 'dog',
  154. rules: [
  155. {
  156. type: 'empty',
  157. prompt: 'You must have a dog to add'
  158. },
  159. {
  160. type: 'contains[fluffy]',
  161. prompt: 'I only want you to add fluffy dogs!'
  162. },
  163. {
  164. type: 'not[mean]',
  165. prompt: 'Why would you add a mean dog to the list?'
  166. }
  167. ]
  168. }
  169. })
  170. ;
  171. $form
  172. .form()
  173. ;
  174. };
  175. // attach ready event
  176. $(document)
  177. .ready(semantic.validateForm.ready)
  178. ;