D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
vitalityhealth
/
public_html
/
superadmin
/
js
/
examples
/
Filename :
examples.ecommerce.form.js
back
Copy
(function($){'use strict';var initializeDropzone=function(){$('#dropzone-form-image').dropzone({url:'/upload.php',addRemoveLinks:true,init:function(){if($('#dropzone-form-image').hasClass('dz-filled')){var dropzoneObj=Dropzone.forElement("#dropzone-form-image"),mockFile={name:"Image Name",size:12345};dropzoneObj.displayExistingFile(mockFile,'img/products/product-1.jpg');}}}).addClass('dropzone initialized');} $(document).ready(function(){if($('#dropzone-form-image').get(0)){initializeDropzone();}});$(window).on('ecommerce.sidebar.overlay.show',function(){if($('#dropzone-form-image').get(0)){initializeDropzone();}});$(document).on('click','.ecommerce-attribute-add-new',function(e){e.preventDefault();var html=''+ '<div class="form-group row justify-content-center ecommerce-attribute-row">'+ '<div class="col-xl-3">'+ '<label class="control-label">Name</label>'+ '<input type="text" class="form-control form-control-modern" name="attName" value="" />'+ '<div class="checkbox mt-3 mb-3 mb-lg-0">'+ '<label class="my-2">'+ '<input type="checkbox" name="attVisible" value="">'+ 'Visible on the item page'+ '</label>'+ '</div>'+ '</div>'+ '<div class="col-xl-6">'+ '<a href="#" class="ecommerce-attribute-remove text-color-danger float-end">Remove</a>'+ '<label class="control-label">Value(s)</label>'+ '<textarea class="form-control form-control-modern" name="attValue" rows="4" placeholder="Enter some text, or some attributes by | separating values"></textarea>'+ '</div>'+ '</div>'+ '';$('.ecommerce-attributes-wrapper').append(html);});$(document).on('click','.ecommerce-attribute-remove',function(e){e.preventDefault();$(this).closest('.ecommerce-attribute-row').remove();});var ecommerceFormValidate=function(){var $form=$('.ecommerce-form');$form.validate({ignore:'',invalidHandler:function(form,validator){var errors=validator.numberOfInvalids();if(errors){$('.form-control.error').each(function(){var tab_id=$(this).closest('.tab-pane').attr('id');$('.nav-link[href="#'+tab_id+'"]').trigger('click');return false;});}},submitHandler:function(form){var formData=$form.serializeArray(),formFieldsData={};$(formData).each(function(index,obj){if(obj.name!='attName'&&obj.name!='attVisible'&&obj.name!='attValue'){formFieldsData[obj.name]=obj.value;}});var attsArray=[];$('.ecommerce-attribute-row').each(function(){var $row=$(this);attsArray.push({attName:$row.find('input[name="attName"]').val(),attVisible:$row.find('input[name="attVisible"]').is(':checked')?true:false,attValue:$row.find('textarea[name="attValue"]').val()});});if(attsArray.length>0){formFieldsData.atts=attsArray;} if($('#dropzone-form-image').get(0)){var dropzoneObj=Dropzone.forElement("#dropzone-form-image");if(typeof dropzoneObj!='undefined'&&dropzoneObj.files.length>0){var imagesArr=[];for(var i=0;i<dropzoneObj.files.length;i++){imagesArr.push({dataURL:dropzoneObj.files[i].dataURL,upload:dropzoneObj.files[i].upload});} formFieldsData.images=imagesArr;}} var $submitButton=$('.submit-button'),submitText=$submitButton.html();$submitButton.html('<i class="bx bx-save text-4 mr-2"></i>'+$submitButton.data('loading-text'));$.ajax({url:'/path/to/register.php',type:'post',data:formFieldsData,}).done(function(){new PNotify({title:'Success',text:'You completed the registration form.',type:'success',addclass:'notification-success',icon:'fas fa-check'});$('.action-buttons').remove();if($form.closest('.ecommerce-form-sidebar-overlay-wrapper').get(0)){$('.ecommerce-form-sidebar-overlay-wrapper').removeClass('show');}else{setTimeout(function(){location.reload();},5000);}}).fail(function(){$submitButton.html(submitText);new PNotify({title:'Error',text:'Unfortunately an error occurred, please try again or contact the website administrator.',type:'error',addclass:'notification-error',icon:'fas fa-times'});});}});} ecommerceFormValidate();$(window).on('ecommerce.sidebar.overlay.show',function(){ecommerceFormValidate();});}(jQuery));