Hello,
Here is my request:
I am building a page to book flight with a standard setup; Inputs are based on the fields (departure, destination, day of departure, time, etc…)
When the client create a one-way journey and submit his request, I have one line created in a dataset. (Via a link connects to submit)
For a round-trip, I would like to be able to create 2 lines in my dataset: One the departure and the other the return?
Any ideas how I can create 2 entry in a database with one submission? Via a hook?
Thanks for your help.
Regards,
Pierre-yves
Hi,
A data-hook is one way to go. If you prefer to use client code, you can use onBeforeSave() .
Hello Ohad,
Thanks for your answer.
in the code I added 2 variables with all the parameters i need to insert the 2 lines
Then, I use 2 times the wixData.insert()
I ve got a side effect: When clicking submit. the required field is not working anymore, lines are inserted even required field are not filled.
How can I test required field has been inputed before insert ?
What do you mean by using onBeforeSave(), I check the doc, I dont really see how I can use it. Have you got an ex ?
Many thanks for your help
Pierre-yves
Here is my piece of code
if ($w(“#bookingRadioGroup”).value === “roundTrip”) {
// Leg 1
let flightLeg1_toInsert = {
“flightId”: todayDate.toISOString().substring(0, 16) + “_LEG1”,
“flightType”: “roundTrip”,
“flightStatus”: “submitted”,
“from”: $w(“#selectionAirportFrom”).value,
“to”: $w(“#selectionAirportTo”).value,
“flightDate”: $w(“#datePickerFrom”).value,
“hourTime”: parseInt($w(“#inputHoursFrom”).value),
“minTime”: parseInt($w(“#inputMinutesFrom”).value),
“numberPassengers”: parseInt($w(“#selectionNbPassengers”).value),
“emailMember”: $w(“#email”).text,
“commentMember”: $w(“#textBoxComments”).value
};
//Insert Leg1 --------> revoir TEST errreur insertion
wixData.insert("flightDataset", flightLeg1_toInsert)
.then((results) => {
let item = results;
console.log(item);
})
.catch((err) => {
let errorMsg = err;
console.log(errorMsg);
});