I created a post the other day, but since then some things have changed (https://www.wix.com/velo/forum/coding-with-velo/insert-and-update-depending-on-if-the-user-has-submitted-information-before/p-1/dl-617db01ef8118300179d80e5?postId=617c3aaa0dced7001763db0e&origin=notification&commentId=617db01ef8118300179d80e5)
I have a button in the header of a website which checks of the user has submitted data to a dataset before. If they have they go to a page with an update form, if they haven’t they go to a page with the submit form, if they’re not signed in they have to sign in. This is working.
The form submission page is now working. There are 3 different input field types on the page. Text input, selection tags and upload buttons. This page is working, all of the fields are uploading to the database as they should be.
The form update page is where I am now struggling. The fields are exactly the same as the submission page.
This is what needs to happen:
-
pre-fill all of the input fields (text, selection tags and upload buttons) with the information from the database.
-
All the fields are pre-filled allowing the user to make the alterations as they need.
-
The user submits and the database updates the information according to the chages that have been made.
This is what I need help with:
-
Pre-filling the form (text, selection tags and upload buttons), with the information from the database
-
updating the database
This is some of the code so far:
function saveProperties() {
$w('#buttonSubmit').disable()
let user = wixUsers.currentUser;
let userId = user.id;
let myQuery = wixData.query("Properties")
let toUpdate = {
"industry2": $w("#checkboxGroup1").value,
"title": $w("#input2").value,
"agentEmail": $w("#input3").value,
"mapLocation": $w("#input36").value,
"businessWebsite": $w("#input35").value,
"facebook": $w("#input33").value,
"instagramLink": $w("#input34").value,
"hoursOfOperation": $w("#input37").value,
"description": $w("#richTextBox1").value,
"familyPic1": familyPhoto1,
"familyPic2": familyPhoto2,
"amenities": $w("#selectionTags1").value,
"_userId": userId
};
myQuery.eq("_owner", userId)
.find()
.then((res)=>{
if(res.items.length>0){
let objResults = res.items[0];
objResults.title = toUpdate.title
objResults.agentEmail = toUpdate.agentEmail
console.log("Data found: ", res.items)
wixData.update("Properties", objResults)
This is the very final step in the project and I’m going to be so happy when it’s done because I would never have been able to achieve something like this a few weeks ago