Adding a reference field on a form submission from a dynamic page

Hello -

I added a form to a dynamic title page from a collection and am trying to include the referenced record on the form submission. It seems like a simple script to write but I don’t have much JS experience.

I have a collection called Profiles and a form to submit a review about the profile with a reference field connecting the two collections. I’m trying to connect the review with the profile through a reference field on the form submission.

Here is the structure:

Dynamic Title page:

Record 1
Data on record 1

Form:
Review data
reference field from record 1= needs to reference record 1
Any suggestions on the script to accomplish this?

What about —> include?
https://www.wix.com/velo/reference/wix-data/wixdataquery/include

…or …
https://www.wix.com/velo/reference/wix-data/queryreferenced

I may have a solution for you that shouldn’t require page code. I’ve been spinning for months trying to get reference fields to work. The Wix documentation about reference fields doesn’t go far enough to lead you to what you need to do. It tells you how to create a reference field but not how to use it on forms to allow the user to select the reference item.

  • Create the reference field in the data collection you’re using for your form. When you create the item, you will be prompted to enter which data collection it references. It will use the primary key of that data collection to fill into your new reference field in the other data collection.

  • On your form, add a dropdown input field. When you connect it to the data collection, choose the field that was the reference field (in my example above it is Mentor). This is done without page code.

  • The user will see a list of the primary items of the data collection you are referencing. Notice what it says above for Connect a List - this is automatically done for you. When designing the primary key for your data collections, keep this in mind that the primary field is what is displayed when you’re updating reference fields.

Furthermore, to display something from the referenced data collection, when you connect a field, you will see the list of data items in the referenced collection.


This works when you reference other data collections or if you want to create a reference to the same data collection (which is what I did above). In my docent roster, I assign mentors to trainees which are also in the same data collection.