I am trying to implement a multi step form in the following way:
- a user starts the form (creating a row in my Questionnaire dataset). In this stage I create a new row in the db and put its id in the current user session like so:
$w.onReady(function () {
let latestRoadMap = null
$w("#startRoadmap").onClick(initRoadmap);
function initRoadmap () {
if (latestRoadMap === null) {
console.info("creating new roadmap")
let newRoadmap = {
"title": "anonymous roadmap"
};
wixData.insert("Questionnaire", newRoadmap)
.then( (results) => {
let item = results;
session.setItem("currentQuestionnaireId", item._id);
console.info(item._id);
} )
.catch( (err) => {
let errorMsg = err;
} );
}
}
});
- Create a page for each step that I want in the form, and when a user clicks on “next” grab the id from the session and update the relevant column in that row in the db (protection_type in this case) with the value from the user input element (radioGroup1 in this example). I implemented like so:
$w("#button1").onClick( (event) => {
console.info("reading questionnaire id from session")
console.info(session.getItem("currentQuestionnaireId"))
wixData.get("Questionnaire", session.getItem("currentQuestionnaireId"))
.then( (item) => {
console.info("updating questionnaire")
item.protection_type = $w("#radioGroup1").value;
wixData.update("Questionnaire", item);
console.info("item updated");
console.info(item.protection_type);
} )
.catch( (err) => {
let errorMsg = err;
} );
wixLocation.to("/questionnaire-2")
});
I can see that the log of the questionnaire id is coming back as expected and prints to the console, but the relevant row is not updated and the whole block in the .then() section is not being run ( I dont see the “updating questionnare” log in the console.)
What am I doing wrong?