pre-fill form and then let toUpdate

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:

  1. pre-fill all of the input fields (text, selection tags and upload buttons) with the information from the database.

  2. All the fields are pre-filled allowing the user to make the alterations as they need.

  3. 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

Okay, so I’m now at a point where the page for updating information is holding the value for all of the fields apart from the file upload fields.

How do I get the file upload fields to prefill with what is already in the database?

function saveProperties() {
    $w('#buttonSubmit').disable();
    let user = wixUsers.currentUser;    //<---here you get the USER GOOD!
    let userId = user.id;               //<---here you get the USER-ID GOOD!
    let myQuery = wixData.query("Properties") //<--- here you get all data from your PROPERTIES-DB, GOOD!
    myQuery.eq("_owner", userId).find()
    .then((res)=>{console.log("RESULTS: ", res);
        //not so good!
        /*
        let toUpdate = {
            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
        };
        */

        // using instead....(direct way)
        let items = res.items; console.log("ITEMS: ", items);
        if(items.length>0){console.log("Length > 0 !");
            let firstItem = items[0];
            firstItem.title =           $w("#input2").value;
            firstItem.agentEmail =      $w("#input3").value;
            firstItem._userId =         userId
            firstItem.industry2 =       $w("#checkboxGroup1").value;
            firstItem.mapLocation =     $w("#input36").value;
            firstItem.businessWebsite = $w("#input35").value
            firstItem.facebook =        $w("#input33").value
            firstItem.instagramLink =   $w("#input34").value
            firstItem.hoursOfOperation= $w("#input37").value;
            firstItem.description =     $w("#richTextBox1").value
            firstItem.familyPic1 =      familyPhoto1;   // where does this come from ?
            firstItem.familyPic2 =      familyPhoto2;   // where does this come from ?
            firstItem.amenities =       $w("#selectionTags1").value;
            //--------------------------------------------------------------------------
            wixData.update("Properties", firstItem) 
        }
    });

Where do these values come from ?

 firstItem.familyPic1 = familyPhoto1;   // where does this come from ?
 firstItem.familyPic2 = familyPhoto2;   // where does this come from ?

Where do you declare → familyPhoto1 / familyPhoto2 ???

How do I get the file upload fields to prefill with what is already in the database?
Which are your → file upload fields
How does it look like inside your database?

Just you know the structure of your own database.