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.

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