暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

wizard-ex-create-deal.js 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /**
  2. * Form Wizard
  3. */
  4. 'use strict';
  5. (function () {
  6. // flatpickrRange
  7. const flatpickrRange = document.querySelector('#dealDuration');
  8. if (flatpickrRange) {
  9. flatpickrRange.flatpickr({
  10. mode: 'range'
  11. });
  12. }
  13. // Init custom option check
  14. window.Helpers.initCustomOptionCheck();
  15. // Vertical Wizard
  16. // --------------------------------------------------------------------
  17. const wizardCreateDeal = document.querySelector('#wizard-create-deal');
  18. if (typeof wizardCreateDeal !== undefined && wizardCreateDeal !== null) {
  19. // Wizard form
  20. const wizardCreateDealForm = wizardCreateDeal.querySelector('#wizard-create-deal-form');
  21. // Wizard steps
  22. const wizardCreateDealFormStep1 = wizardCreateDealForm.querySelector('#deal-type');
  23. const wizardCreateDealFormStep2 = wizardCreateDealForm.querySelector('#deal-details');
  24. const wizardCreateDealFormStep3 = wizardCreateDealForm.querySelector('#deal-usage');
  25. const wizardCreateDealFormStep4 = wizardCreateDealForm.querySelector('#review-complete');
  26. // Wizard next prev button
  27. const wizardCreateDealNext = [].slice.call(wizardCreateDealForm.querySelectorAll('.btn-next'));
  28. const wizardCreateDealPrev = [].slice.call(wizardCreateDealForm.querySelectorAll('.btn-prev'));
  29. let validationStepper = new Stepper(wizardCreateDeal, {
  30. linear: true
  31. });
  32. // Deal Type
  33. const FormValidation1 = FormValidation.formValidation(wizardCreateDealFormStep1, {
  34. fields: {
  35. dealAmount: {
  36. validators: {
  37. notEmpty: {
  38. message: 'Please enter amount'
  39. },
  40. numeric: {
  41. message: 'The amount must be a number'
  42. }
  43. }
  44. },
  45. dealRegion: {
  46. validators: {
  47. notEmpty: {
  48. message: 'Please select region'
  49. }
  50. }
  51. }
  52. },
  53. plugins: {
  54. trigger: new FormValidation.plugins.Trigger(),
  55. bootstrap5: new FormValidation.plugins.Bootstrap5({
  56. // Use this for enabling/changing valid/invalid class
  57. // eleInvalidClass: '',
  58. eleValidClass: '',
  59. rowSelector: '.form-control-validation'
  60. }),
  61. autoFocus: new FormValidation.plugins.AutoFocus(),
  62. submitButton: new FormValidation.plugins.SubmitButton()
  63. }
  64. }).on('core.form.valid', function () {
  65. // Jump to the next step when all fields in the current step are valid
  66. validationStepper.next();
  67. });
  68. // select2 (Region)
  69. const dealRegion = $('#dealRegion');
  70. if (dealRegion.length) {
  71. dealRegion.wrap('<div class="position-relative"></div>');
  72. dealRegion
  73. .select2({
  74. placeholder: 'Select an region',
  75. dropdownParent: dealRegion.parent()
  76. })
  77. .on('change', function () {
  78. // Revalidate the region field when an option is chosen
  79. FormValidation1.revalidateField('dealRegion');
  80. });
  81. }
  82. // Deal Details
  83. const FormValidation2 = FormValidation.formValidation(wizardCreateDealFormStep2, {
  84. fields: {
  85. // * Validate the fields here based on your requirements
  86. dealTitle: {
  87. validators: {
  88. notEmpty: {
  89. message: 'Please enter deal title'
  90. }
  91. }
  92. },
  93. dealCode: {
  94. validators: {
  95. notEmpty: {
  96. message: 'Please enter deal code'
  97. },
  98. stringLength: {
  99. min: 4,
  100. max: 10,
  101. message: 'The deal code must be more than 4 and less than 10 characters long'
  102. },
  103. regexp: {
  104. regexp: /^[A-Z0-9]+$/,
  105. message: 'The deal code can only consist of capital alphabetical and number'
  106. }
  107. }
  108. }
  109. },
  110. plugins: {
  111. trigger: new FormValidation.plugins.Trigger(),
  112. bootstrap5: new FormValidation.plugins.Bootstrap5({
  113. // Use this for enabling/changing valid/invalid class
  114. // eleInvalidClass: '',
  115. eleValidClass: '',
  116. rowSelector: '.form-control-validation'
  117. }),
  118. autoFocus: new FormValidation.plugins.AutoFocus(),
  119. submitButton: new FormValidation.plugins.SubmitButton()
  120. }
  121. }).on('core.form.valid', function () {
  122. // Jump to the next step when all fields in the current step are valid
  123. validationStepper.next();
  124. });
  125. // select2 (Offered Item)
  126. const dealOfferedItem = $('#dealOfferedItem');
  127. if (dealOfferedItem.length) {
  128. dealOfferedItem.wrap('<div class="position-relative"></div>');
  129. dealOfferedItem
  130. .select2({
  131. placeholder: 'Select an offered item',
  132. dropdownParent: dealOfferedItem.parent()
  133. })
  134. .on('change', function () {
  135. // Revalidate the field if needed when an option is chosen
  136. // FormValidation2.revalidateField('dealOfferedItem');
  137. });
  138. }
  139. // Deal Usage
  140. const FormValidation3 = FormValidation.formValidation(wizardCreateDealFormStep3, {
  141. fields: {
  142. // * Validate the fields here based on your requirements
  143. },
  144. plugins: {
  145. trigger: new FormValidation.plugins.Trigger(),
  146. bootstrap5: new FormValidation.plugins.Bootstrap5({
  147. // Use this for enabling/changing valid/invalid class
  148. // eleInvalidClass: '',
  149. eleValidClass: '',
  150. rowSelector: '.form-control-validation'
  151. }),
  152. autoFocus: new FormValidation.plugins.AutoFocus(),
  153. submitButton: new FormValidation.plugins.SubmitButton()
  154. }
  155. }).on('core.form.valid', function () {
  156. validationStepper.next();
  157. });
  158. // Deal Usage
  159. const FormValidation4 = FormValidation.formValidation(wizardCreateDealFormStep4, {
  160. fields: {
  161. // * Validate the fields here based on your requirements
  162. },
  163. plugins: {
  164. trigger: new FormValidation.plugins.Trigger(),
  165. bootstrap5: new FormValidation.plugins.Bootstrap5({
  166. // Use this for enabling/changing valid/invalid class
  167. // eleInvalidClass: '',
  168. eleValidClass: '',
  169. rowSelector: '.form-control-validation'
  170. }),
  171. autoFocus: new FormValidation.plugins.AutoFocus(),
  172. submitButton: new FormValidation.plugins.SubmitButton()
  173. }
  174. }).on('core.form.valid', function () {
  175. // You can submit the form
  176. // wizardCreateDealForm.submit()
  177. // or send the form data to server via an Ajax request
  178. // To make the demo simple, I just placed an alert
  179. alert('Submitted..!!');
  180. });
  181. wizardCreateDealNext.forEach(item => {
  182. item.addEventListener('click', event => {
  183. // When click the Next button, we will validate the current step
  184. switch (validationStepper._currentIndex) {
  185. case 0:
  186. FormValidation1.validate();
  187. break;
  188. case 1:
  189. FormValidation2.validate();
  190. break;
  191. case 2:
  192. FormValidation3.validate();
  193. break;
  194. case 3:
  195. FormValidation4.validate();
  196. break;
  197. default:
  198. break;
  199. }
  200. });
  201. });
  202. wizardCreateDealPrev.forEach(item => {
  203. item.addEventListener('click', event => {
  204. switch (validationStepper._currentIndex) {
  205. case 3:
  206. validationStepper.previous();
  207. break;
  208. case 2:
  209. validationStepper.previous();
  210. break;
  211. case 1:
  212. validationStepper.previous();
  213. break;
  214. case 0:
  215. default:
  216. break;
  217. }
  218. });
  219. });
  220. }
  221. })();