Açıklama Yok
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.

pages-auth-multisteps.js 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. /**
  2. * Page auth register multi-steps
  3. */
  4. 'use strict';
  5. // Select2 (jquery)
  6. $(function () {
  7. var select2 = $('.select2');
  8. // select2
  9. if (select2.length) {
  10. select2.each(function () {
  11. var $this = $(this);
  12. $this.wrap('<div class="position-relative"></div>');
  13. $this.select2({
  14. placeholder: 'Select an country',
  15. dropdownParent: $this.parent()
  16. });
  17. });
  18. }
  19. });
  20. // Multi Steps Validation
  21. // --------------------------------------------------------------------
  22. document.addEventListener('DOMContentLoaded', function (e) {
  23. (function () {
  24. const stepsValidation = document.querySelector('#multiStepsValidation');
  25. if (typeof stepsValidation !== undefined && stepsValidation !== null) {
  26. // Multi Steps form
  27. const stepsValidationForm = stepsValidation.querySelector('#multiStepsForm');
  28. // Form steps
  29. const stepsValidationFormStep1 = stepsValidationForm.querySelector('#accountDetailsValidation');
  30. const stepsValidationFormStep2 = stepsValidationForm.querySelector('#personalInfoValidation');
  31. const stepsValidationFormStep3 = stepsValidationForm.querySelector('#billingLinksValidation');
  32. // Multi steps next prev button
  33. const stepsValidationNext = [].slice.call(stepsValidationForm.querySelectorAll('.btn-next'));
  34. const stepsValidationPrev = [].slice.call(stepsValidationForm.querySelectorAll('.btn-prev'));
  35. const multiStepsExDate = document.querySelector('.multi-steps-exp-date'),
  36. multiStepsCvv = document.querySelector('.multi-steps-cvv'),
  37. multiStepsMobile = document.querySelector('.multi-steps-mobile'),
  38. multiStepsPincode = document.querySelector('.multi-steps-pincode'),
  39. multiStepsCard = document.querySelector('.multi-steps-card');
  40. // Expiry Date Mask
  41. if (multiStepsExDate) {
  42. multiStepsExDate.addEventListener('input', event => {
  43. multiStepsExDate.value = formatDate(event.target.value, {
  44. date: true,
  45. delimiter: '/',
  46. datePattern: ['m', 'y']
  47. });
  48. });
  49. registerCursorTracker({
  50. input: multiStepsExDate,
  51. delimiter: '/'
  52. });
  53. }
  54. // CVV
  55. if (multiStepsCvv) {
  56. multiStepsCvv.addEventListener('input', event => {
  57. const cleanValue = event.target.value.replace(/\D/g, '');
  58. multiStepsCvv.value = formatNumeral(cleanValue, {
  59. numeral: true,
  60. numeralPositiveOnly: true
  61. });
  62. });
  63. }
  64. // Mobile
  65. if (multiStepsMobile) {
  66. multiStepsMobile.addEventListener('input', event => {
  67. const cleanValue = event.target.value.replace(/\D/g, '');
  68. multiStepsMobile.value = formatGeneral(cleanValue, {
  69. blocks: [3, 3, 4],
  70. delimiters: [' ', ' ']
  71. });
  72. });
  73. registerCursorTracker({
  74. input: multiStepsMobile,
  75. delimiter: ' '
  76. });
  77. }
  78. // Pincode
  79. if (multiStepsPincode) {
  80. multiStepsPincode.addEventListener('input', event => {
  81. multiStepsPincode.value = formatNumeral(event.target.value, {
  82. delimiter: '',
  83. numeral: true
  84. });
  85. });
  86. }
  87. // Credit Card
  88. if (multiStepsCard) {
  89. multiStepsCard.addEventListener('input', event => {
  90. multiStepsCard.value = formatCreditCard(event.target.value);
  91. const cleanValue = event.target.value.replace(/\D/g, '');
  92. let cardType = getCreditCardType(cleanValue);
  93. if (cardType && cardType !== 'unknown' && cardType !== 'general') {
  94. document.querySelector('.card-type').innerHTML =
  95. `<img src="${assetsPath}img/icons/payments/${cardType}-cc.png" height="20"/>`;
  96. } else {
  97. document.querySelector('.card-type').innerHTML = '';
  98. }
  99. });
  100. registerCursorTracker({
  101. input: multiStepsCard,
  102. delimiter: ' '
  103. });
  104. }
  105. let validationStepper = new Stepper(stepsValidation, {
  106. linear: true
  107. });
  108. // Account details
  109. const multiSteps1 = FormValidation.formValidation(stepsValidationFormStep1, {
  110. fields: {
  111. multiStepsUsername: {
  112. validators: {
  113. notEmpty: {
  114. message: 'Please enter username'
  115. },
  116. stringLength: {
  117. min: 6,
  118. max: 30,
  119. message: 'The name must be more than 6 and less than 30 characters long'
  120. },
  121. regexp: {
  122. regexp: /^[a-zA-Z0-9 ]+$/,
  123. message: 'The name can only consist of alphabetical, number and space'
  124. }
  125. }
  126. },
  127. multiStepsEmail: {
  128. validators: {
  129. notEmpty: {
  130. message: 'Please enter email address'
  131. },
  132. emailAddress: {
  133. message: 'The value is not a valid email address'
  134. }
  135. }
  136. },
  137. multiStepsPass: {
  138. validators: {
  139. notEmpty: {
  140. message: 'Please enter password'
  141. }
  142. }
  143. },
  144. multiStepsConfirmPass: {
  145. validators: {
  146. notEmpty: {
  147. message: 'Confirm Password is required'
  148. },
  149. identical: {
  150. compare: function () {
  151. return stepsValidationFormStep1.querySelector('[name="multiStepsPass"]').value;
  152. },
  153. message: 'The password and its confirm are not the same'
  154. }
  155. }
  156. }
  157. },
  158. plugins: {
  159. trigger: new FormValidation.plugins.Trigger(),
  160. bootstrap5: new FormValidation.plugins.Bootstrap5({
  161. // Use this for enabling/changing valid/invalid class
  162. // eleInvalidClass: '',
  163. eleValidClass: '',
  164. rowSelector: '.form-control-validation'
  165. }),
  166. autoFocus: new FormValidation.plugins.AutoFocus(),
  167. submitButton: new FormValidation.plugins.SubmitButton()
  168. },
  169. init: instance => {
  170. instance.on('plugins.message.placed', function (e) {
  171. if (e.element.parentElement.classList.contains('input-group')) {
  172. e.element.parentElement.insertAdjacentElement('afterend', e.messageElement);
  173. }
  174. });
  175. }
  176. }).on('core.form.valid', function () {
  177. // Jump to the next step when all fields in the current step are valid
  178. validationStepper.next();
  179. });
  180. // Personal info
  181. const multiSteps2 = FormValidation.formValidation(stepsValidationFormStep2, {
  182. fields: {
  183. multiStepsFirstName: {
  184. validators: {
  185. notEmpty: {
  186. message: 'Please enter first name'
  187. }
  188. }
  189. },
  190. multiStepsAddress: {
  191. validators: {
  192. notEmpty: {
  193. message: 'Please enter your address'
  194. }
  195. }
  196. }
  197. },
  198. plugins: {
  199. trigger: new FormValidation.plugins.Trigger(),
  200. bootstrap5: new FormValidation.plugins.Bootstrap5({
  201. // Use this for enabling/changing valid/invalid class
  202. // eleInvalidClass: '',
  203. eleValidClass: '',
  204. rowSelector: function (field, ele) {
  205. // field is the field name
  206. // ele is the field element
  207. switch (field) {
  208. case 'multiStepsFirstName':
  209. case 'multiStepsAddress':
  210. return '.form-control-validation';
  211. default:
  212. return '.row';
  213. }
  214. }
  215. }),
  216. autoFocus: new FormValidation.plugins.AutoFocus(),
  217. submitButton: new FormValidation.plugins.SubmitButton()
  218. }
  219. }).on('core.form.valid', function () {
  220. // Jump to the next step when all fields in the current step are valid
  221. validationStepper.next();
  222. });
  223. // Social links
  224. const multiSteps3 = FormValidation.formValidation(stepsValidationFormStep3, {
  225. fields: {
  226. multiStepsCard: {
  227. validators: {
  228. notEmpty: {
  229. message: 'Please enter card number'
  230. }
  231. }
  232. }
  233. },
  234. plugins: {
  235. trigger: new FormValidation.plugins.Trigger(),
  236. bootstrap5: new FormValidation.plugins.Bootstrap5({
  237. // Use this for enabling/changing valid/invalid class
  238. // eleInvalidClass: '',
  239. eleValidClass: '',
  240. rowSelector: function (field, ele) {
  241. // field is the field name
  242. // ele is the field element
  243. switch (field) {
  244. case 'multiStepsCard':
  245. return '.form-control-validation';
  246. default:
  247. return '.form-control-validation';
  248. }
  249. }
  250. }),
  251. autoFocus: new FormValidation.plugins.AutoFocus(),
  252. submitButton: new FormValidation.plugins.SubmitButton()
  253. },
  254. init: instance => {
  255. instance.on('plugins.message.placed', function (e) {
  256. if (e.element.parentElement.classList.contains('input-group')) {
  257. e.element.parentElement.insertAdjacentElement('afterend', e.messageElement);
  258. }
  259. });
  260. }
  261. }).on('core.form.valid', function () {
  262. // You can submit the form
  263. // stepsValidationForm.submit()
  264. // or send the form data to server via an Ajax request
  265. // To make the demo simple, I just placed an alert
  266. alert('Submitted..!!');
  267. });
  268. stepsValidationNext.forEach(item => {
  269. item.addEventListener('click', event => {
  270. // When click the Next button, we will validate the current step
  271. switch (validationStepper._currentIndex) {
  272. case 0:
  273. multiSteps1.validate();
  274. break;
  275. case 1:
  276. multiSteps2.validate();
  277. break;
  278. case 2:
  279. multiSteps3.validate();
  280. break;
  281. default:
  282. break;
  283. }
  284. });
  285. });
  286. stepsValidationPrev.forEach(item => {
  287. item.addEventListener('click', event => {
  288. switch (validationStepper._currentIndex) {
  289. case 2:
  290. validationStepper.previous();
  291. break;
  292. case 1:
  293. validationStepper.previous();
  294. break;
  295. case 0:
  296. default:
  297. break;
  298. }
  299. });
  300. });
  301. }
  302. })();
  303. });