| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326 |
- /**
- * Page auth register multi-steps
- */
-
- 'use strict';
-
- // Select2 (jquery)
- $(function () {
- var select2 = $('.select2');
-
- // select2
- if (select2.length) {
- select2.each(function () {
- var $this = $(this);
- $this.wrap('<div class="position-relative"></div>');
- $this.select2({
- placeholder: 'Select an country',
- dropdownParent: $this.parent()
- });
- });
- }
- });
-
- // Multi Steps Validation
- // --------------------------------------------------------------------
- document.addEventListener('DOMContentLoaded', function (e) {
- (function () {
- const stepsValidation = document.querySelector('#multiStepsValidation');
- if (typeof stepsValidation !== undefined && stepsValidation !== null) {
- // Multi Steps form
- const stepsValidationForm = stepsValidation.querySelector('#multiStepsForm');
- // Form steps
- const stepsValidationFormStep1 = stepsValidationForm.querySelector('#accountDetailsValidation');
- const stepsValidationFormStep2 = stepsValidationForm.querySelector('#personalInfoValidation');
- const stepsValidationFormStep3 = stepsValidationForm.querySelector('#billingLinksValidation');
- // Multi steps next prev button
- const stepsValidationNext = [].slice.call(stepsValidationForm.querySelectorAll('.btn-next'));
- const stepsValidationPrev = [].slice.call(stepsValidationForm.querySelectorAll('.btn-prev'));
-
- const multiStepsExDate = document.querySelector('.multi-steps-exp-date'),
- multiStepsCvv = document.querySelector('.multi-steps-cvv'),
- multiStepsMobile = document.querySelector('.multi-steps-mobile'),
- multiStepsPincode = document.querySelector('.multi-steps-pincode'),
- multiStepsCard = document.querySelector('.multi-steps-card');
-
- // Expiry Date Mask
- if (multiStepsExDate) {
- multiStepsExDate.addEventListener('input', event => {
- multiStepsExDate.value = formatDate(event.target.value, {
- date: true,
- delimiter: '/',
- datePattern: ['m', 'y']
- });
- });
- registerCursorTracker({
- input: multiStepsExDate,
- delimiter: '/'
- });
- }
-
- // CVV
- if (multiStepsCvv) {
- multiStepsCvv.addEventListener('input', event => {
- const cleanValue = event.target.value.replace(/\D/g, '');
- multiStepsCvv.value = formatNumeral(cleanValue, {
- numeral: true,
- numeralPositiveOnly: true
- });
- });
- }
-
- // Mobile
- if (multiStepsMobile) {
- multiStepsMobile.addEventListener('input', event => {
- const cleanValue = event.target.value.replace(/\D/g, '');
- multiStepsMobile.value = formatGeneral(cleanValue, {
- blocks: [3, 3, 4],
- delimiters: [' ', ' ']
- });
- });
- registerCursorTracker({
- input: multiStepsMobile,
- delimiter: ' '
- });
- }
-
- // Pincode
- if (multiStepsPincode) {
- multiStepsPincode.addEventListener('input', event => {
- multiStepsPincode.value = formatNumeral(event.target.value, {
- delimiter: '',
- numeral: true
- });
- });
- }
-
- // Credit Card
- if (multiStepsCard) {
- multiStepsCard.addEventListener('input', event => {
- multiStepsCard.value = formatCreditCard(event.target.value);
- const cleanValue = event.target.value.replace(/\D/g, '');
- let cardType = getCreditCardType(cleanValue);
- if (cardType && cardType !== 'unknown' && cardType !== 'general') {
- document.querySelector('.card-type').innerHTML =
- `<img src="${assetsPath}img/icons/payments/${cardType}-cc.png" height="20"/>`;
- } else {
- document.querySelector('.card-type').innerHTML = '';
- }
- });
- registerCursorTracker({
- input: multiStepsCard,
- delimiter: ' '
- });
- }
-
- let validationStepper = new Stepper(stepsValidation, {
- linear: true
- });
-
- // Account details
- const multiSteps1 = FormValidation.formValidation(stepsValidationFormStep1, {
- fields: {
- multiStepsUsername: {
- validators: {
- notEmpty: {
- message: 'Please enter username'
- },
- stringLength: {
- min: 6,
- max: 30,
- message: 'The name must be more than 6 and less than 30 characters long'
- },
- regexp: {
- regexp: /^[a-zA-Z0-9 ]+$/,
- message: 'The name can only consist of alphabetical, number and space'
- }
- }
- },
- multiStepsEmail: {
- validators: {
- notEmpty: {
- message: 'Please enter email address'
- },
- emailAddress: {
- message: 'The value is not a valid email address'
- }
- }
- },
- multiStepsPass: {
- validators: {
- notEmpty: {
- message: 'Please enter password'
- }
- }
- },
- multiStepsConfirmPass: {
- validators: {
- notEmpty: {
- message: 'Confirm Password is required'
- },
- identical: {
- compare: function () {
- return stepsValidationFormStep1.querySelector('[name="multiStepsPass"]').value;
- },
- message: 'The password and its confirm are not the same'
- }
- }
- }
- },
- plugins: {
- trigger: new FormValidation.plugins.Trigger(),
- bootstrap5: new FormValidation.plugins.Bootstrap5({
- // Use this for enabling/changing valid/invalid class
- // eleInvalidClass: '',
- eleValidClass: '',
- rowSelector: '.form-control-validation'
- }),
- autoFocus: new FormValidation.plugins.AutoFocus(),
- submitButton: new FormValidation.plugins.SubmitButton()
- },
- init: instance => {
- instance.on('plugins.message.placed', function (e) {
- if (e.element.parentElement.classList.contains('input-group')) {
- e.element.parentElement.insertAdjacentElement('afterend', e.messageElement);
- }
- });
- }
- }).on('core.form.valid', function () {
- // Jump to the next step when all fields in the current step are valid
- validationStepper.next();
- });
-
- // Personal info
- const multiSteps2 = FormValidation.formValidation(stepsValidationFormStep2, {
- fields: {
- multiStepsFirstName: {
- validators: {
- notEmpty: {
- message: 'Please enter first name'
- }
- }
- },
- multiStepsAddress: {
- validators: {
- notEmpty: {
- message: 'Please enter your address'
- }
- }
- }
- },
- plugins: {
- trigger: new FormValidation.plugins.Trigger(),
- bootstrap5: new FormValidation.plugins.Bootstrap5({
- // Use this for enabling/changing valid/invalid class
- // eleInvalidClass: '',
- eleValidClass: '',
- rowSelector: function (field, ele) {
- // field is the field name
- // ele is the field element
- switch (field) {
- case 'multiStepsFirstName':
- case 'multiStepsAddress':
- return '.form-control-validation';
- default:
- return '.row';
- }
- }
- }),
- autoFocus: new FormValidation.plugins.AutoFocus(),
- submitButton: new FormValidation.plugins.SubmitButton()
- }
- }).on('core.form.valid', function () {
- // Jump to the next step when all fields in the current step are valid
- validationStepper.next();
- });
-
- // Social links
- const multiSteps3 = FormValidation.formValidation(stepsValidationFormStep3, {
- fields: {
- multiStepsCard: {
- validators: {
- notEmpty: {
- message: 'Please enter card number'
- }
- }
- }
- },
- plugins: {
- trigger: new FormValidation.plugins.Trigger(),
- bootstrap5: new FormValidation.plugins.Bootstrap5({
- // Use this for enabling/changing valid/invalid class
- // eleInvalidClass: '',
- eleValidClass: '',
- rowSelector: function (field, ele) {
- // field is the field name
- // ele is the field element
- switch (field) {
- case 'multiStepsCard':
- return '.form-control-validation';
-
- default:
- return '.form-control-validation';
- }
- }
- }),
- autoFocus: new FormValidation.plugins.AutoFocus(),
- submitButton: new FormValidation.plugins.SubmitButton()
- },
- init: instance => {
- instance.on('plugins.message.placed', function (e) {
- if (e.element.parentElement.classList.contains('input-group')) {
- e.element.parentElement.insertAdjacentElement('afterend', e.messageElement);
- }
- });
- }
- }).on('core.form.valid', function () {
- // You can submit the form
- // stepsValidationForm.submit()
- // or send the form data to server via an Ajax request
- // To make the demo simple, I just placed an alert
- alert('Submitted..!!');
- });
-
- stepsValidationNext.forEach(item => {
- item.addEventListener('click', event => {
- // When click the Next button, we will validate the current step
- switch (validationStepper._currentIndex) {
- case 0:
- multiSteps1.validate();
- break;
-
- case 1:
- multiSteps2.validate();
- break;
-
- case 2:
- multiSteps3.validate();
- break;
-
- default:
- break;
- }
- });
- });
-
- stepsValidationPrev.forEach(item => {
- item.addEventListener('click', event => {
- switch (validationStepper._currentIndex) {
- case 2:
- validationStepper.previous();
- break;
-
- case 1:
- validationStepper.previous();
- break;
-
- case 0:
-
- default:
- break;
- }
- });
- });
- }
- })();
- });
|