Ingen beskrivning
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

form-layouts.js 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /**
  2. * Form Layout Vertical
  3. */
  4. 'use strict';
  5. (function () {
  6. const phoneMaskList = document.querySelectorAll('.phone-mask'),
  7. creditCardMask = document.querySelector('.credit-card-mask'),
  8. expiryDateMask = document.querySelector('.expiry-date-mask'),
  9. cvvMask = document.querySelector('.cvv-code-mask'),
  10. datepickerList = document.querySelectorAll('.dob-picker'),
  11. formCheckInputPayment = document.querySelectorAll('.form-check-input-payment');
  12. // Phone Number
  13. if (phoneMaskList) {
  14. phoneMaskList.forEach(function (phoneMask) {
  15. phoneMask.addEventListener('input', event => {
  16. const cleanValue = event.target.value.replace(/\D/g, '');
  17. phoneMask.value = formatGeneral(cleanValue, {
  18. blocks: [3, 3, 4],
  19. delimiters: [' ', ' ']
  20. });
  21. });
  22. registerCursorTracker({
  23. input: phoneMask,
  24. delimiter: ' '
  25. });
  26. });
  27. }
  28. // Credit Card
  29. if (creditCardMask) {
  30. creditCardMask.addEventListener('input', event => {
  31. creditCardMask.value = formatCreditCard(event.target.value);
  32. const cleanValue = event.target.value.replace(/\D/g, '');
  33. let cardType = getCreditCardType(cleanValue);
  34. if (cardType && cardType !== 'unknown' && cardType !== 'general') {
  35. document.querySelector('.card-type').innerHTML =
  36. `<img src="${assetsPath}img/icons/payments/${cardType}-cc.png" height="20"/>`;
  37. } else {
  38. document.querySelector('.card-type').innerHTML = '';
  39. }
  40. });
  41. registerCursorTracker({
  42. input: creditCardMask,
  43. delimiter: ' '
  44. });
  45. }
  46. // Expiry Date Mask
  47. if (expiryDateMask) {
  48. expiryDateMask.addEventListener('input', event => {
  49. expiryDateMask.value = formatDate(event.target.value, {
  50. delimiter: '/',
  51. datePattern: ['m', 'y']
  52. });
  53. });
  54. registerCursorTracker({
  55. input: expiryDateMask,
  56. delimiter: '/'
  57. });
  58. }
  59. // CVV
  60. if (cvvMask) {
  61. cvvMask.addEventListener('input', event => {
  62. const cleanValue = event.target.value.replace(/\D/g, '');
  63. cvvMask.value = formatNumeral(cleanValue, {
  64. numeral: true,
  65. numeralPositiveOnly: true
  66. });
  67. });
  68. }
  69. // Flat Picker Birth Date
  70. if (datepickerList) {
  71. datepickerList.forEach(function (datepicker) {
  72. datepicker.flatpickr({
  73. monthSelectorType: 'static'
  74. });
  75. });
  76. }
  77. // Toggle CC Payment Method based on selected option
  78. if (formCheckInputPayment) {
  79. formCheckInputPayment.forEach(function (paymentInput) {
  80. paymentInput.addEventListener('change', function (e) {
  81. const paymentInputValue = e.target.value;
  82. if (paymentInputValue === 'credit-card') {
  83. document.querySelector('#form-credit-card').classList.remove('d-none');
  84. } else {
  85. document.querySelector('#form-credit-card').classList.add('d-none');
  86. }
  87. });
  88. });
  89. }
  90. })();
  91. // select2 (jquery)
  92. $(function () {
  93. // Init custom option check
  94. window.Helpers.initCustomOptionCheck();
  95. // Select2 Country
  96. var select2 = $('.select2');
  97. if (select2.length) {
  98. select2.each(function () {
  99. var $this = $(this);
  100. $this.wrap('<div class="position-relative"></div>').select2({
  101. placeholder: 'Select value',
  102. dropdownParent: $this.parent()
  103. });
  104. });
  105. }
  106. });