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.

pages-auth.js 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /**
  2. * Pages Authentication
  3. */
  4. 'use strict';
  5. document.addEventListener('DOMContentLoaded', function () {
  6. (() => {
  7. const formAuthentication = document.querySelector('#formAuthentication');
  8. // Form validation for Add new record
  9. if (formAuthentication && typeof FormValidation !== 'undefined') {
  10. FormValidation.formValidation(formAuthentication, {
  11. fields: {
  12. username: {
  13. validators: {
  14. notEmpty: {
  15. message: 'Please enter username'
  16. },
  17. stringLength: {
  18. min: 6,
  19. message: 'Username must be more than 6 characters'
  20. }
  21. }
  22. },
  23. email: {
  24. validators: {
  25. notEmpty: {
  26. message: 'Please enter your email'
  27. },
  28. emailAddress: {
  29. message: 'Please enter a valid email address'
  30. }
  31. }
  32. },
  33. 'email-username': {
  34. validators: {
  35. notEmpty: {
  36. message: 'Please enter email / username'
  37. },
  38. stringLength: {
  39. min: 6,
  40. message: 'Username must be more than 6 characters'
  41. }
  42. }
  43. },
  44. password: {
  45. validators: {
  46. notEmpty: {
  47. message: 'Please enter your password'
  48. },
  49. stringLength: {
  50. min: 6,
  51. message: 'Password must be more than 6 characters'
  52. }
  53. }
  54. },
  55. 'confirm-password': {
  56. validators: {
  57. notEmpty: {
  58. message: 'Please confirm password'
  59. },
  60. identical: {
  61. compare: () => formAuthentication.querySelector('[name="password"]').value,
  62. message: 'The password and its confirmation do not match'
  63. },
  64. stringLength: {
  65. min: 6,
  66. message: 'Password must be more than 6 characters'
  67. }
  68. }
  69. },
  70. terms: {
  71. validators: {
  72. notEmpty: {
  73. message: 'Please agree to terms & conditions'
  74. }
  75. }
  76. }
  77. },
  78. plugins: {
  79. trigger: new FormValidation.plugins.Trigger(),
  80. bootstrap5: new FormValidation.plugins.Bootstrap5({
  81. eleValidClass: '',
  82. rowSelector: '.form-control-validation'
  83. }),
  84. submitButton: new FormValidation.plugins.SubmitButton(),
  85. defaultSubmit: new FormValidation.plugins.DefaultSubmit(),
  86. autoFocus: new FormValidation.plugins.AutoFocus()
  87. },
  88. init: instance => {
  89. instance.on('plugins.message.placed', e => {
  90. if (e.element.parentElement.classList.contains('input-group')) {
  91. e.element.parentElement.insertAdjacentElement('afterend', e.messageElement);
  92. }
  93. });
  94. }
  95. });
  96. }
  97. // Two Steps Verification for numeral input mask
  98. const numeralMaskElements = document.querySelectorAll('.numeral-mask');
  99. // Format function for numeral mask
  100. const formatNumeral = value => value.replace(/\D/g, ''); // Only keep digits
  101. if (numeralMaskElements.length > 0) {
  102. numeralMaskElements.forEach(numeralMaskEl => {
  103. numeralMaskEl.addEventListener('input', event => {
  104. numeralMaskEl.value = formatNumeral(event.target.value);
  105. });
  106. });
  107. }
  108. })();
  109. });