$(document).ready(function(){ //change input type to date $('[data-input-type="date"]').attr('type','date'); //hide element on load $('[data-ms-form="consent-error"]').hide(); $('[data-btn="remove"]').hide(); }); //Multistep form custom navigations //Custom slider next button $('[data-btn="ms-slider-next-custom"]').on('click',function(){ $('[data-btn="ms-slider-next"]').click(); }); //Custom slider previous button $('[data-btn="ms-slider-prev-custom"]').on('click',function(){ $('[data-btn="ms-slider-prev"]').click(); }); //Custom slider nav $('.ms-step-nav-item').each(function(){ $(this).on('click',function(){ var msStep = ($(this).index())+2; $(this).closest('[data-form="ms"]').find('.w-slider-dot:nth-child('+msStep+')').click(); }); }); //Custom submit button $('[data-btn="ms-submit-custom"]').on('click',function(){ $('[data-btn="ms-submit"]').click(); }); //Form logic //Add child item var childTitle = $('[data-form-group="additional-children-list"]').find('[data-label="group-item"]').text(); var childName = $('[data-form-group="additional-children-list"]').find('[data-form-input="add-child-name"]').attr('data-name'); var childdob = $('[data-form-group="additional-children-list"]').find('[data-form-input="add-child-dob"]').attr('data-name'); var childgender = $('[data-form-group="additional-children-list"]').find('[data-form-input="add-child-gender"]').attr('data-name'); var childethnic = $('[data-form-group="additional-children-list"]').find('[data-form-input="add-child-ethnicity"]').attr('data-name'); var childreferral = $('[data-form-group="additional-children-list"]').find('[data-form-input="add-child-referral"]').attr('data-name'); $('[data-btn="add-child"]').on('click',function(){ //clone inputs group var childObj = $('[data-form-group="additional-children-list"]').find('.ms-form-group:first-child').clone(true); $('[data-form-group="additional-children-list"]').append(childObj); //visibility of removal btn $('[data-btn="remove"]').each(function(){ if($(this).closest('.ms-form-group').not(':first-child')){ $(this).show(); } if($(this).closest('.ms-form-group').is(':first-child')){ $(this).hide(); } }); //empty new item $('[data-form-group="additional-children-list"]').find('.ms-form-group:last-child').find('input').val(''); $('[data-form-group="additional-children-list"]').find('.ms-form-group:last-child').find('input[type="checkbox"]').prop('checked',false); //Rename inputs and labels $('[data-form-group="additional-children-list"]').find('.ms-form-group').each(function(){ var childNumber = ($(this).index())+1; $(this).find('[data-label="group-item"]').text(childTitle+' '+childNumber); $(this).find('[data-form-input="add-child-name"]').attr({ 'name': childName+' '+childNumber, 'data-name': childName+' '+childNumber, }); $(this).find('[data-form-input="add-child-dob"]').attr({ 'name': childdob+' '+childNumber, 'data-name': childdob+' '+childNumber, }); $(this).find('[data-form-input="add-child-gender"]').attr({ 'name': childgender+' '+childNumber, 'data-name': childgender+' '+childNumber, }); $(this).find('[data-form-input="add-child-ethnicity"]').attr({ 'name': childethnic+' '+childNumber, 'data-name': childethnic+' '+childNumber, }); $(this).find('[data-form-input="add-child-referral"]').attr({ 'name': childreferral+' '+childNumber, 'data-name': childreferral+' '+childNumber, }); }); }); //Add caregiver item var cgTitle = $('[data-form-group="additional-cg-list"]').find('[data-label="group-item"]').text(); var cgName = $('[data-form-group="additional-cg-list"]').find('[data-form-input="add-cg-name"]').attr('data-name'); var cgPhone = $('[data-form-group="additional-cg-list"]').find('[data-form-input="add-cg-contact"]').attr('data-name'); var cgEmail = $('[data-form-group="additional-cg-list"]').find('[data-form-input="add-cg-email"]').attr('data-name'); var cgRelationship = $('[data-form-group="additional-cg-list"]').find('[data-form-input="add-cg-relationship"]').attr('data-name'); var cgdob = $('[data-form-group="additional-cg-list"]').find('[data-form-input="add-cg-dob"]').attr('data-name'); var cglive = $('[data-form-group="additional-cg-list"]').find('[data-form-input="add-cg-live"]').attr('data-name'); var cgaddress = $('[data-form-group="additional-cg-list"]').find('[data-form-input="add-cg-address"]').attr('data-name'); $('[data-btn="add-cg"]').on('click',function(){ //clone inputs group var cgObj = $('[data-form-group="additional-cg-list"]').find('.ms-form-group:first-child').clone(true); $('[data-form-group="additional-cg-list"]').append(cgObj); //visibility of removal btn $('[data-btn="remove"]').each(function(){ if($(this).closest('.ms-form-group').not(':first-child')){ $(this).show(); } if($(this).closest('.ms-form-group').is(':first-child')){ $(this).hide(); } }); //empty new item $('[data-form-group="additional-cg-list"]').find('.ms-form-group:last-child').find('input').val(''); $('[data-form-group="additional-cg-list"]').find('.ms-form-group:last-child').find('input[type="checkbox"]').prop('checked',false); //Rename inputs and labels $('[data-form-group="additional-cg-list"]').find('.ms-form-group').each(function(){ var cgNum = ($(this).index())+1; $(this).find('[data-label="group-item"]').text(cgTitle+' '+cgNum); $(this).find('[data-form-input="add-cg-name"]').attr({ 'name': cgName+' '+cgNum, 'data-name': cgName+' '+cgNum, }); $(this).find('[data-form-input="add-cg-contact"]').attr({ 'name': cgPhone+' '+cgNum, 'data-name': cgPhone+' '+cgNum, }); $(this).find('[data-form-input="add-cg-email"]').attr({ 'name': cgEmail+' '+cgNum, 'data-name': cgEmail+' '+cgNum, }); $(this).find('[data-form-input="add-cg-relationship"]').attr({ 'name': cgRelationship+' '+cgNum, 'data-name': cgRelationship+' '+cgNum, }); $(this).find('[data-form-input="add-cg-dob"]').attr({ 'name': cgdob+' '+cgNum, 'data-name': cgdob+' '+cgNum, }); $(this).find('[data-form-input="add-cg-live"]').attr({ 'name': cglive+' '+cgNum, 'data-name': cglive+' '+cgNum, }); $(this).find('[data-form-input="add-cg-address"]').attr({ 'name': cgaddress+' '+cgNum, 'data-name': cgaddress+' '+cgNum, }); }); }); //remove item $('[data-btn="remove"]').each(function(){ $(this).on('click',function(){ $(this).closest('.ms-form-group').remove(); }); }); //Deny proceed without consent /* $('[data-radio-btn="consent-no"]').on('click',function(){ $('[data-ms-form="consent-error"]').show(); $(this).parents(".ms-step-top-content").animate({scrollTop: $('[data-ms-form="consent-error"]').position().top}, 500); }); $('[data-radio-btn="consent-yes"]').on('click',function(){ $('[data-ms-form="consent-error"]').hide(); }); */ //next and submit button validation $(document).ready(function(){ setInterval(function(){ //if first slide /* if($('[data-slider="ms-form"]').find('.w-slider-dot:first-child').hasClass('w-active')){ $('[data-btn="ms-slider-prev-custom"],[data-element="ms-slider-nav"]').hide(); $('[data-btn="ms-slider-next-custom"]').find('.ms-step-btn-label').text('Get started'); $('[data-btn="ms-slider-next-custom"]').show(); $('[data-btn="ms-submit-custom"]').hide(); } if(!$('[data-slider="ms-form"]').find('.w-slider-dot:first-child').hasClass('w-active') && !$('[data-slider="ms-form"]').find('.w-slider-dot:last-child').hasClass('w-active')){ $('[data-btn="ms-slider-prev-custom"],[data-element="ms-slider-nav"]').show(); $('[data-btn="ms-slider-next-custom"]').find('.ms-step-btn-label').text('Next'); } if($('[data-slider="ms-form"]').find('.w-slider-dot:last-child').hasClass('w-active')){ $('[data-btn="ms-slider-prev-custom"],[data-element="ms-slider-nav"]').show(); $('[data-btn="ms-submit-custom"]').find('.ms-step-btn-label').text('Submit'); } */ //steps indicator $('.ms-step-nav-item').each(function(){ var stepInd = $(this).index(); var activeStep = $('[data-form="ms"]').find('.w-slider-dot.w-active').index(); if(stepInd < activeStep){ $(this).addClass('is--active'); $(this).removeAttr('pointer-events'); } if(stepInd >= activeStep){ $(this).removeClass('is--active'); $(this).attr('pointer-events','none'); } }); var msform = $('[data-slider="ms-form"]'); var msprevc = $('[data-btn="ms-slider-prev-custom"]'); var msnextc = $('[data-btn="ms-slider-next-custom"]'); var mssubmitc = $('[data-btn="ms-submit-custom"]'); var msnav = $('[data-element="ms-slider-nav"]'); var currentStep = $('[data-slider="ms-form"]').find('.w-slider-dot.w-active').index()+1; if(currentStep == 1) { msprevc.hide(); msnav.hide(); mssubmitc.hide(); mssubmitc.removeClass('is--disabled'); msnextc.show(); msnextc.find('.ms-step-btn-label').text('Get started'); mssubmitc.find('.ms-step-btn-label').text('Next'); } if(currentStep == 2) { //invalid if($('.ms-form-slide:nth-child(2)').find('input[type="checkbox"][required]:checked').length == 0) { mssubmitc.show(); mssubmitc.addClass('is--disabled'); msnextc.hide(); $('.ms-form-slide:nth-child(2)').find('input[type="checkbox"]').attr('required',true); } //valid if($('.ms-form-slide:nth-child(2)').find('input[type="checkbox"][required]:checked').length > 0) { mssubmitc.hide(); mssubmitc.removeClass('is--disabled'); msnextc.show(); $('.ms-form-slide:nth-child(2)').find('input[type="checkbox"]').attr('required',false); } msprevc.show(); msnav.show(); msnextc.find('.ms-step-btn-label').text('Next'); mssubmitc.find('.ms-step-btn-label').text('Next'); } if(currentStep == 3) { function countEmptyRequiredInputs() { var $emptyRequiredInputs = $('.ms-form-slide:nth-child(3)').find(':input[required]').filter(function() { return !$(this).val(); }); return $emptyRequiredInputs.length; } var emptyInputsCount = countEmptyRequiredInputs(); //invalid if(emptyInputsCount > 0 || $('.ms-form-slide:nth-child(3)').find('input[type="radio"][required]:checked').length == 0) { mssubmitc.show(); mssubmitc.addClass('is--disabled'); msnextc.hide(); } //valid if(emptyInputsCount == 0 && $('.ms-form-slide:nth-child(3)').find('input[type="radio"][required]:checked').length == 1) { mssubmitc.hide(); mssubmitc.removeClass('is--disabled'); msnextc.show(); } console.log('Step'+currentStep+'='+emptyInputsCount); msprevc.show(); msnav.show(); msnextc.find('.ms-step-btn-label').text('Next'); mssubmitc.find('.ms-step-btn-label').text('Next'); } if(currentStep == 4) { function countEmptyRequiredInputs() { var $emptyRequiredInputs = $('.ms-form-slide:nth-child(4)').find(':input[required]').filter(function() { return !$(this).val(); }); return $emptyRequiredInputs.length; } var emptyInputsCount = countEmptyRequiredInputs(); //invalid if(emptyInputsCount > 0) { mssubmitc.show(); mssubmitc.addClass('is--disabled'); msnextc.hide(); } //valid if(emptyInputsCount == 0) { mssubmitc.hide(); mssubmitc.removeClass('is--disabled'); msnextc.show(); } console.log('Step'+currentStep+'='+emptyInputsCount); msprevc.show(); msnav.show(); msnextc.find('.ms-step-btn-label').text('Next'); mssubmitc.find('.ms-step-btn-label').text('Next'); } if(currentStep == 5) { function countEmptyRequiredInputs() { var $emptyRequiredInputs = $('.ms-form-slide:nth-child(5)').find(':input[required]').filter(function() { return !$(this).val(); }); return $emptyRequiredInputs.length; } var emptyInputsCount = countEmptyRequiredInputs(); //invalid if(emptyInputsCount > 0) { mssubmitc.show(); mssubmitc.addClass('is--disabled'); msnextc.hide(); } //valid if(emptyInputsCount == 0) { mssubmitc.hide(); mssubmitc.removeClass('is--disabled'); msnextc.show(); } console.log('Step'+currentStep+'='+emptyInputsCount); msprevc.show(); msnav.show(); msnextc.find('.ms-step-btn-label').text('Next'); mssubmitc.find('.ms-step-btn-label').text('Next'); } if(currentStep == 6) { //invalid if($('.ms-form-slide:nth-child(6)').find('input[type="checkbox"][required]:checked').length == 0) { mssubmitc.show(); mssubmitc.addClass('is--disabled'); msnextc.hide(); $('.ms-form-slide:nth-child(6)').find('input[type="checkbox"]').attr('required',true); } //valid if($('.ms-form-slide:nth-child(6)').find('input[type="checkbox"][required]:checked').length > 0) { mssubmitc.hide(); mssubmitc.removeClass('is--disabled'); msnextc.show(); $('.ms-form-slide:nth-child(6)').find('input[type="checkbox"]').attr('required',false); } msprevc.show(); msnav.show(); msnextc.find('.ms-step-btn-label').text('Next'); mssubmitc.find('.ms-step-btn-label').text('Next'); } if(currentStep == 7) { msprevc.show(); msnav.show(); msnextc.find('.ms-step-btn-label').text('Next'); mssubmitc.find('.ms-step-btn-label').text('Next'); } if(currentStep == 8) { msprevc.show(); msnav.show(); mssubmitc.show(); mssubmitc.removeClass('is--disabled'); msnextc.hide(); msnextc.find('.ms-step-btn-label').text('Next'); mssubmitc.find('.ms-step-btn-label').text('Submit'); } }, 150); }); //Review labels and information $('[data-slider="ms-form"]').find('input,select,textarea').each(function(){ $(this).on('keyup input change click focusin focusout',function(){ $('[data-review-label="name"]').text($('[data-review-input="name"]').val()); $('[data-review-label="relationship"]').text($('[data-review-input="relationship"]').val()); $('[data-review-label="contact-phone"]').text($('[data-review-input="contact-phone"]').val()); $('[data-review-label="email"]').text($('[data-review-input="email"]').val()); $('[data-review-label="address"]').text($('[data-review-input="address"]').val()); }); });