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.

143 lines
2.6 KiB

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