Dropdown value connected to database reference field

I’m creating a page to insert an item into a custom database. The database stores ‘Releases’ by a single musician. In the primary database, there is a reference field (‘release_type’) linked to a secondary database. Items in the secondary database include ‘Live’ and ‘Album’. I have added both datasets to my ‘Add Release’ page. I created a dropdown to set the value of the reference field (‘release_type’), and connected it to my primary dataset (‘Releases’). I’ve set the ‘Connect a List’ section to connect to the secondary dataset, with values connected to the ‘Title’ field. I am unable to connect the primary dataset’s “Value connects to” property to the reference field in my primary database. I can only set it to a Text or Number field. How do I set up the dropdown to update the reference field ‘release_type’ with the value selected from the secondary database?

2 Likes

You have a good point there. It is not supported yet.

You can probably do so with coding, reading the second collection (the referenced collection) using code, creating options , setting as the value the _id from the referenced collection and as the label the title (or primary field) from the referenced collection. From this point, things should be working as the dropdown will display the labels while storing the values - which are the _id of the referenced collection.

1 Like

Yoav, I was trying to achieve exactly the same. Isn´t this a must-have?

2 Likes

I can’t say enough what an ommission in design is in not allowing a lookup through a items in a referenced table. Referenced table are most commonly used for this feature. WIX people, get serious!

1 Like

and to suggest doing this in code, is equally a bad idea.

1 Like

Hello guys,
I ran into the same problem and I have just managed to sort it out. I’ll put my code below.
You would have to change the dropdown references, the dataset reference and the field reference (after contain) to make the first function work.
The second function needs, in addition, changes on the lines with labels and values.
Hope it helps!

export function dropdown1_change(event, $w) {
let myValue = $w(“#dropdown1”).value;
console.log(myValue);

let dropdownSelIndex = $w(“#dropdown1”).selectedIndex;
$w(“#dataset1”).setFilter(wixData.filter().contains(“floweringPeriod”,$w(“#dropdown1”).value))

.catch((error) => { 
	let errorMsg = error.message; 
	let code = error.code; 

}); 

}
export function dropdown2_mouseIn(event, $w) {
$w(“#dropdown2”).options = [
{“label”: “Many colors available”, “value”: “5d55b3c9-20c9-4be9-883f-5114346ec902”},
{“label”: “Deep purple”, “value”: “3c2e0a76-7dfb-48f1-b813-8d5a5c968516”}
];
}
export function dropdown2_change(event, $w) {
let myValue = $w(“#dropdown2”).value;
console.log(myValue);

let dropdownSelIndex = $w(“#dropdown2”).selectedIndex;
$w(“#dataset1”).setFilter(wixData.filter().contains(“flowerColor”,$w(“#dropdown2”).value))

.catch((error) => { 
	let errorMsg = error.message; 
	let code = error.code; 

}); 

}

1 Like

maybe you can help - I tried you’re code in my site but it doesn’t do it - The difference is like that I’m tring to load a reference field into the new record of the main database A-UsedItmes.
maybe you can help - I tried you’re code in my site but it doesn’t do it - The difference is like that I’m trying to load a reference field into the new record of the main database A-UsedItmes.nother new record)

// For full API documentation, including code examples, visit http://wix.to/94BuAAs
import wixData from ‘wix-data’;

$w.onReady(function () {
//TODO: write your page related code here…

});

let toInsert = “”;

export function dropdown6_change(event, $w) {
// Query from dropdown change event
wixData.query(“TypeUsed”)
.eq(“title”, $w(“#dropdown6”).value)

   .find() 
   .then(  (results) => { 
   	let firstItem = results.items[0]; //First Item Results 
		 toInsert = {"usedType": firstItem}; 

   	wixData.insert("A-UsedItems", toInsert) 
   
   	.then( (results) => { 
		let firstItem = results [0]; 
	} ) 
	.catch( (err) => { 
		let errorMsg = err; 
	} ); 
} ); 
}
1 Like

fill the drop-down manually