setFieldValues() or bulkSave

I have multiple identical forms. I need to submit them all at once. I cannot seem to figure out which one to use. I have attached pictures and code below please help. Any help is appreciated.

import wixData from 'wix-data';

function getInfo() {

    $w('#dataset1').setFieldValues({

 "studentName": $w('#input1').value,
 "date": $w('#datePicker2').value,
 "class": $w('#dropdown2').value,
    })

 
    $w('#dataset1').next()

     $w('#dataset1').setFieldValues({

 "studentName": $w('#input4').value,
 "date": $w('#datePicker3').value,
 "class": $w('#dropdown3').value,
    })

    $w('#dataset1').save()
}

export function button1_click(event) {
    getInfo() 
}

Hi,
If I understand you correctly, a user can fill in several forms for each student,
and you wish to save them all in once in your database, mean your dataset is on write-only mode.

  1. use $w ( ‘#dataset1’). onReady() function and inside this event call to getInfo() function (maybe your code not working cause the dataset is not ready yet)

  2. if you wish to save these items in your database, I suggest to insert the forms to repeater and inside the onClick event go over all the repeater’s items and insert each one to the collection
    view : https://www.wix.com/corvid/reference/$w.Repeater.html#forEachItem
    https://www.wix.com/corvid/reference/wix-data.html#insert

Best,
Sapir

This was a big help. Now I’m working with the repeater and the forEachItem() function. It loops through the correct number of times but I’m doing something wrong because only the first students name is being passed through the loop

import wixData from 'wix-data';

function getInfo() {

    $w('#repeater1').forEachItem(($item, itemData, index) => {
 if ($w('#studentName').value !== null){
 /*
                    $item("input4").value = itemData.studentName
                    $w('#dataset1').setFieldValue("studentName", $item("input4").value)   
                    $w('#dataset1').save()
                    */
                    console.log($w('#studentName').value)
            }

    });

}



export function button1_click(event) {
    getInfo()

}

Hi,

Can you send a URL to your site?

Best,
Sapir

did you try using $item instead of $w inside the forEachItem callback function?

https://tmsimsedu.wixsite.com/theprocess

I was informed by someone who works for wix the repeaters do not allow user input. It is something they are working on. I started from scratch and hit a similar problem if you have a second to check it out please do. https://tmsimsedu.wixsite.com/theprocess
Any advice is appreciated