I have a Real Estate website, with each property having a unique property ID. When someone selects the “Request More Information” form, I need that unique property ID to be associated to the request.
Hello realestateindominicanrepublic,
“How do I automatically populate an ID field in a “Request More Information” form with data from a Repeater.”
I hope i understood it right…
Your repeater just shows the data which is in your data-collection.
And your data-collection is connected with the data-set to your repeater.
So it’s not the repeater you are looking for!
Just think for a minute.
What you wanna do? (some facts)
- You want to fill automatic a field/textfield in your form.
- The data which you want to perform, is in your database (data-collection).
- So you have to read out your specific data from a specific COLUM (REFERENCE) of your DATA-Collection.
Database: ------> connected with ----> dataset-1
index | real estate-ID | real estate-object
01 | 000-000-001 | 2-family-house (6-floors)
02 | 000-000-002 | 1-family-house (4-floors)
03 | 000-000-003 | 1-family-house (2-floors)
Here you will find, what you can do with datasets…
https://www.wix.com/corvid/reference/wix-dataset.Dataset.html
And here you will see, what you can do with data-collection…
https://www.wix.com/corvid/reference/wix-data.html
If your request more info form is being opened in a lightbox for example, then you can just simply do something like this, as stated in the Wix API Reference for Repeater.
https://www.wix.com/corvid/reference/$w.Repeater.html
Retrieve Repeater Item Data When Clicked
Each repeated item in a repeater has a Container element that holds all of its repeated elements. To retrieve the data associated with a specific repeated item when it is clicked, create an onClick event handler for the item’s Container. Depending on how you populated the repeater with data, you either use the connected dataset or the repeater’s data array to retrieve the clicked item’s data in the event handler.
import wixWindow from 'wix-window';
import wixData from 'wix-data';
$w.onReady(function () {
$w("#repeater1").onItemReady( ($w, itemData, index) => {
$w("#container1").onClick((event) => {
wixWindow.openLightbox('Lightbox', $w('#dataset1').getCurrentItem());
});
});
});
Make sure that you change the repeater id to what your repeater id is called.
Also change the lightbox name to the actual lightbox name in your site structure and not the element id name.
Along with replacing the dataset with your own datasets id name that is on the dataset connector on your page.
Then on your lightbox, have this code…
import {lightbox} from 'wix-window';
$w.onReady( () => {
let item = lightbox.getContext();
// For a text box use this... //
$w("#text1").text = item.fieldkey;
// For a user input use this... //
$w("#input1").value = item.fieldkey;
});
Make sure field key above is changed to the specific field in the dataset that contains your properties id, so if it was field name of Property Id, your field key would be propertyId and you would set it as item.propertyId
Also, depending if you are auto filling a text box or a user input, you will need to change the appropriate choice to your own elements id name.
Finally, as you are manually setting it by code, you will need to add the setFieldValue() function from Wix Dataset API if you are intending on saving this user request form again.
To do that simply add this line after the choice of text box or user input and before the closing });
$w("#myDataset").setFieldValue("propertyId", $w("#idname").value);
Same as before you will need to change the dataset id to the dataset that you saving the users form into.
Along with ‘propertyId’ needs to be changed to the appropriate field key in that dataset where you are saving the properties id into.
Then just change idname in the value part to the element id of either the text box or the user input that you have used already.
If you have a submit button on the form which is already connected to the dataset to save your user request submissions, then you don’t need to add a save() function into your used code as stated in the Wix API Reference, as you are doing this save with the submit button itself.
You might want to have a good read of the Wix API Reference for Repeater already linked in previous post and these Wix pages about repeaters too, so that you can get a good understanding of how they work in code.
https://support.wix.com/en/corvid-by-wix/wix-repeaters-with-corvid