| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- /**
- * Pages Authentication
- */
- 'use strict';
-
- document.addEventListener('DOMContentLoaded', function () {
- (() => {
- const formAuthentication = document.querySelector('#formAuthentication');
-
- // Form validation for Add new record
- if (formAuthentication && typeof FormValidation !== 'undefined') {
- FormValidation.formValidation(formAuthentication, {
- fields: {
- username: {
- validators: {
- notEmpty: {
- message: 'Please enter username'
- },
- stringLength: {
- min: 6,
- message: 'Username must be more than 6 characters'
- }
- }
- },
- email: {
- validators: {
- notEmpty: {
- message: 'Please enter your email'
- },
- emailAddress: {
- message: 'Please enter a valid email address'
- }
- }
- },
- 'email-username': {
- validators: {
- notEmpty: {
- message: 'Please enter email / username'
- },
- stringLength: {
- min: 6,
- message: 'Username must be more than 6 characters'
- }
- }
- },
- password: {
- validators: {
- notEmpty: {
- message: 'Please enter your password'
- },
- stringLength: {
- min: 6,
- message: 'Password must be more than 6 characters'
- }
- }
- },
- 'confirm-password': {
- validators: {
- notEmpty: {
- message: 'Please confirm password'
- },
- identical: {
- compare: () => formAuthentication.querySelector('[name="password"]').value,
- message: 'The password and its confirmation do not match'
- },
- stringLength: {
- min: 6,
- message: 'Password must be more than 6 characters'
- }
- }
- },
- terms: {
- validators: {
- notEmpty: {
- message: 'Please agree to terms & conditions'
- }
- }
- }
- },
- plugins: {
- trigger: new FormValidation.plugins.Trigger(),
- bootstrap5: new FormValidation.plugins.Bootstrap5({
- eleValidClass: '',
- rowSelector: '.form-control-validation'
- }),
- submitButton: new FormValidation.plugins.SubmitButton(),
- defaultSubmit: new FormValidation.plugins.DefaultSubmit(),
- autoFocus: new FormValidation.plugins.AutoFocus()
- },
- init: instance => {
- instance.on('plugins.message.placed', e => {
- if (e.element.parentElement.classList.contains('input-group')) {
- e.element.parentElement.insertAdjacentElement('afterend', e.messageElement);
- }
- });
- }
- });
- }
-
- // Two Steps Verification for numeral input mask
- const numeralMaskElements = document.querySelectorAll('.numeral-mask');
-
- // Format function for numeral mask
- const formatNumeral = value => value.replace(/\D/g, ''); // Only keep digits
-
- if (numeralMaskElements.length > 0) {
- numeralMaskElements.forEach(numeralMaskEl => {
- numeralMaskEl.addEventListener('input', event => {
- numeralMaskEl.value = formatNumeral(event.target.value);
- });
- });
- }
- })();
- });
|