How to set a text field that is connected to a dataset to be a input to a form subbmission?

This is a form that i would like to submit. In my form database, i collect 5 information: Name, Phone, Date, Time, and Car Model. “Car Model” is the issue i am having at the moment. This form is located in the CMS item page, where is shows all the relevant details of this particular car. and this form allows customer to make an appointment to test drive this particular car. As this form is present in all the items page, i would like to know which car is the customer referring to.


In the photo above is my form. The text “Car Brand and Model” is link to my car inventory dataset which will shows the actual car details for this item. Can it be written into my “Appointment” dataset? as shown below.

I tried the following

  1. using a “text” to link as shown in picture 1

  2. using a “input box” and prefill it with current item name. but when submitted, the Car Model is not recorded as shown in Picture 2

  1. using a “text” to link as shown in picture 1

  2. using a “input box” and prefill it with current item name. but when submitted, the Car Model is not recorded as shown in Picture 2

You are describing some attempts to manage your issue?
But you do not show the code you have written for it!

Did you use code at all to solve your issue?

  1. I assume that you will have even 2-datasets which are related to your above described issue, don’t you?

How do i know this?

As this form is present in all the items page…
Looks like a → DYNAMIC-PAGE (and every dynamic-page has a dynamic-dataset).

So what do know else about your project-setup?

  1. You will also have an ordinary dataset…

Which will do the savings to your → “Test Drive Appointment” DATABASE
(YES → DATABASE , please do yourself a favour and don’t call it COLLECTION).

  1. So now you have a conflict, because you are using two different DATASETS, which do not really communicate with each other.

  2. Let’ generate some helping code, which will solve our problem…

First o all what you will need is to wait, for…
a) page-ready…
b) dynamic-dataset ready…
c) ordinary-dataset-ready…

This is always the first thing you will do inside your code, when working on a wix-page using datasets or dynamic-datasets.

$w.onReady(()=>{
	$w('#dynamicDataset').onReady(()=>{

	});

	$w('#dataset1').onReady(()=>{

	});
});

Now let’s get first the data of your dynamic-page…

$w.onReady(()=>{
	$w('#dynamicDataset').onReady(()=>{
		let curItem=$w('#dynamicDataset').getCurrentItem();
		console.log("Current-Item: ", curItem);
	});

	$w('#dataset1').onReady(()=>{

	});
});

You already can should be able to see some results when preview your project setup inside the wix-editors PREVIEW-MODE.

Surely you will get something like → […] or —> {…}.
Clicking onto the results, the object will open —> showing everything whats inside.

So what exactly you wanted to do one more time?
Oh yes → you wanted to save data, including the data from your dynamic page, right?

So since we already know the data of the dynamic page (we have stored it already inside a → VARIABLE), now we nedd to generate the saving process, after we have clicked onto our SUBMISSION-BUTTON…

There are 2-different ways of how to do so…
In your case you have connected the button inside the PROPERTY-PANEL, that means, coding an already existing function, would make no sense, it would just create a doubled uneccessary functionality.

But how to proceed now? We can’t code it?

Yes of course we can!!! But what do we need to be able to do so?

So here we go…(what is that?)

$w("#myDataset").onBeforeSave( () => {
  console.log("Continuing save");
  return true;
});

This is a → HOOK (onBeforeSave()-Hook) → which will give us the opertunity to proceed our saving.

Let’s implement it into our code…

$w.onReady(()=>{
	$w('#dynamicDataset').onReady(()=>{
		let curItem=$w('#dynamicDataset').getCurrentItem();
		console.log("Current-Item: ", curItem);
	});

	$w('#dataset1').onReady(()=>{
	
	});
	
	$w('#dataset1').onBeforeSave(()=> {
		//----------------------------
		//additional code here...
		//additional code here...
		//additional code here...
		//additional code here...
		//additional code here...
		//----------------------------
  		console.log("Continuing save");
  		return true;
	});	
});

Ok, what next ?

  1. You will have to tell the function, what has to be done → BEFORE-SAVING !!!
    Inside the shown code-block…
//----------------------------
	//additional code here...
	//additional code here...
	//additional code here...
	//additional code here...
	//additional code here...
//----------------------------

This for you will use…
setFieldValue - Velo API Reference - Wix.com

Fixed-static-example:

$w('#dataset1').setFieldValue("carModel", "My-New-Car-Model");

Yes, we added the right DATABASE-FIELD, but wait, you don’t want to have a static/fixed value.

You want to have the “car-model-data” from your dynamic page!!!
Didn’t we already got this data ?

let curItem=$w('#dynamicDataset').getCurrentItem();
console.log("Current-Item: ", curItem);

So, now we can make it DYNAMIC, right? —> RIGHT !!!

$w('#dataset1').setFieldValue("carModel", xxxxxxxxxxxxxxxxxx);

Continue… (replace the xxxxx and make it dynamic).

!!! Complete the code !!!

Hi Code-Ninja, thank you very much. I have tried it and it work like a charm.

No problem :stuck_out_tongue_winking_eye:

Hi Code-Ninja, just wondering if you are able to help with this issue. https://community.wix.com/velo/forum/coding-with-velo/how-to-hide-elements-in-repeaters-if-the-data-is-false