How to insert a field value in wix database which is connected with another dataset

Hi Guys,

Totally new in wix and in the coding world, still trying to learn and develop my own website. I am facing an issue and I am sure that I am missing something here, need your guidance and support.

Scenario :

I have a repeater , having some fields which are connected with “Pkg_TourPackage” Database

The field “day1” is populating the Daywise Plan of my tour package in the wix website

Requirement :

Whenever user clicks the submit button, the day wise plan values needs to be inserted in database, not the text in the text field.

Issue :

System is not inserting the connected values in the database, it is inserting the "text"of the Field.

Code:

$w ( ‘#btnQuote’ ). onClick ( async ( Event , $w )=>{
let firstname = ( $w ( “#firstName” ). value );
let lastname = ( $w ( “#lastName” ). value );
let daywiseplan = ( $w ( “#day1” ). text );
let packagename = ( $w ( “#text7” ). text );
let insert ={
“firstName” : firstname ,
“title” : packagename ,
“daywiseplan” : daywiseplan
}
wixData . save ( “Trial1” , insert )
})

Repeater :

Custom Form :

Output :

daywiseplan output is getting inserted as “1”, because the actual text of “day1” field is “1”, system is not capturing the connected value.

Is the “Itinerary Overview” and “Confirmation Form” on the same page?

If they are, it is possible you can extract the #day1 value directly from the dataset associated to the repeater using getItems()

Otherwise I would recommend saving and accessing the users itinerary data using Session or Memory storage through Wix-Storage

Yes both are on the same page.

Rather than:

let firstname =( $w ( “#firstName” ). value );

Try:

let firstname = $w ( “#firstName” ). value ;

One way to accomplish this is to use getItems() and build the insert object.

Since you are using a dataset with a repeater, the dataset will contain only the data for the days that are currently displayed.

You could do something like this:

let numberOfDays = 2; //Total Repeater Items

$w.onReady(function () {
    $w('#dataset').onReady(() => {
        $w("#dataset").getItems(0, numberOfDays)
            .then((result) => {
                //Use this to build insert object
                console.log(result);
            });
    });
});

The data in result will look something like this image below and you can use it to build a insert object which gets saved to your collection when the user clicks ‘Get Quote’

You could also use onItemReady() and itemData with the repeater to build the insert object as each row is rendered onto the page.

These are some suggestions and there are likely other ways to accomplish this as well :slight_smile: