Brak opisu
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.

modal-edit-cc.js 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /**
  2. * Edit credit card
  3. */
  4. 'use strict';
  5. document.addEventListener('DOMContentLoaded', function (e) {
  6. (function () {
  7. const editCreditCardMaskEdit = document.querySelector('.credit-card-mask-edit'),
  8. editExpiryDateMaskEdit = document.querySelector('.expiry-date-mask-edit'),
  9. editCVVMaskEdit = document.querySelector('.cvv-code-mask-edit');
  10. // Credit Card
  11. if (editCreditCardMaskEdit) {
  12. editCreditCardMaskEdit.addEventListener('input', event => {
  13. editCreditCardMaskEdit.value = formatCreditCard(event.target.value);
  14. const cleanValue = event.target.value.replace(/\D/g, '');
  15. let cardType = getCreditCardType(cleanValue);
  16. if (cardType && cardType !== 'unknown' && cardType !== 'general') {
  17. document.querySelector('.card-type-edit').innerHTML =
  18. `<img src="${assetsPath}img/icons/payments/${cardType}-cc.png" height="20"/>`;
  19. } else {
  20. document.querySelector('.card-type-edit').innerHTML = '';
  21. }
  22. });
  23. registerCursorTracker({
  24. input: editCreditCardMaskEdit,
  25. delimiter: ' '
  26. });
  27. }
  28. // Expiry Date MaskEdit
  29. if (editExpiryDateMaskEdit) {
  30. editExpiryDateMaskEdit.addEventListener('input', event => {
  31. editExpiryDateMaskEdit.value = formatDate(event.target.value, {
  32. delimiter: '/',
  33. datePattern: ['m', 'y']
  34. });
  35. });
  36. registerCursorTracker({
  37. input: editExpiryDateMaskEdit,
  38. delimiter: '/'
  39. });
  40. }
  41. // CVV MaskEdit
  42. if (editCVVMaskEdit) {
  43. editCVVMaskEdit.addEventListener('input', event => {
  44. const cleanValue = event.target.value.replace(/\D/g, '');
  45. editCVVMaskEdit.value = formatNumeral(cleanValue, {
  46. numeral: true,
  47. numeralPositiveOnly: true
  48. });
  49. });
  50. }
  51. // Credit card form validation
  52. FormValidation.formValidation(document.getElementById('editCCForm'), {
  53. fields: {
  54. modalEditCard: {
  55. validators: {
  56. notEmpty: {
  57. message: 'Please enter your credit card number'
  58. }
  59. }
  60. }
  61. },
  62. plugins: {
  63. trigger: new FormValidation.plugins.Trigger(),
  64. bootstrap5: new FormValidation.plugins.Bootstrap5({
  65. // Use this for enabling/changing valid/invalid class
  66. // eleInvalidClass: '',
  67. eleValidClass: '',
  68. rowSelector: '.form-control-validation'
  69. }),
  70. submitButton: new FormValidation.plugins.SubmitButton(),
  71. // Submit the form when all fields are valid
  72. // defaultSubmit: new FormValidation.plugins.DefaultSubmit(),
  73. autoFocus: new FormValidation.plugins.AutoFocus()
  74. },
  75. init: instance => {
  76. instance.on('plugins.message.placed', function (e) {
  77. //* Move the error message out of the `input-group` element
  78. if (e.element.parentElement.classList.contains('input-group')) {
  79. e.element.parentElement.insertAdjacentElement('afterend', e.messageElement);
  80. }
  81. });
  82. }
  83. });
  84. })();
  85. });