Multi step form

// API Reference: https://www.wix.com/corvid/reference

// “Hello, World!” Example: https://www.wix.com/corvid/hello-world

import wixData from 'wix-data';

$w.onReady(function () {

$w("#formMultiStep").changeState("State1");

});

export function btnContinue_click(event) {

$w("#formMultiStep").changeState("State2");

}

// check fields in State1 to enable Continue button

export function name_input(event) {

checkContinue();

}

export function phone_input(event) {

checkContinue();

}

export function email_input(event) {

checkContinue();

}

function checkContinue() {

if ($w('#name').value.length > 0 && $w('#phone').value.length > 0 && $w('#email').value.length > 0) {

$w('#btnContinue').enable();

} else {

$w('#btnContinue').disable();

}

}

// check fields in State2 to enable Submit button

export function address1_input(event) {

checkSubmit();

}

export function city_input(event) {

checkSubmit();

}

export function state_input(event) {

checkSubmit();

}

export function zip_input(event) {

checkSubmit();

}

function checkSubmit() {

if ($w('#address1').value.length > 0 && $w('#city').value.length > 0 && $w('#state').value.length > 0 && $w('#zip').value.length > 0) {

$w('#btnSubmit').enable();

} else {

$w('#btnSubmit').disable();

}

}

export function btnBack_click(event) {

$w("#formMultiStep").changeState("State1");

}

export function btnSubmit_click(event) {

$w("#formMultiStep").changeState("State3");

saveFormData();

}

// action for Submit buttion

function saveFormData() {

let toSave = {

"name":     $w('#name').value,

"phone":    $w('#phone').value,

"email":    $w('#email').value,

"address1": $w('#address1').value,

"address2": $w('#address2').value,

"city":     $w('#city').value,

"state":    $w('#state').value,

"zip":      $w('#zip').value

};

wixData.save("FormSubmissions", toSave)

.then((results) => {

let item = results; //see item below

})

.catch((err) => {

let errorMsg = err;

});

}