I can't create form that fills reference field. Whaaaat?

Could I create a form which could fill reference field? I’ve added write only dataset to the page and input element and find myself unable to connect value to reference field.

Please help me.

Hey,
You’re right, this feature is missing at the moment - we’re working on it and it should be available soon.
In the meantime, you can achieve that using code.

Даниил Омельченко did you ever figure out the code to achieve this?

I find a workaroud…

I created a “Dropdown” Element and I fulfill with my references items.

$w.onReady( function () {
populateFlags();
});

function populateFlags() {
getElements().then( (allFlags) => {
let flagElements = ;
for ( var i = 0; i < allFlags.items.length; i++) {
let flag= allFlags.items[i];
flagElements .push({label: flag.title, value: flag._id});
}
$w(‘#dropdownFlag’).options = flagElements;
}). catch ( (err) => {
console.log(err);
});
}

Then on change item of data set I update the dropdown

export function datasetPlaces_currentIndexChanged() {
$w(‘#dropdownFlag’).value = $w(‘#datasetPlaces’).getCurrentItem().flag._id;
}

Then on action change of the dropdown (the getFlag is a function I defined to get my flag collection by id)

export function dropdownFlag_change(event, $w) {
getFlag($w(‘#dropdownFlag’).value).then( (flag) => {
// get the current item of my dataset
let place = $w(‘#datasetPlaces’).getCurrentItem();

   // set the flag object to my current place 
    place.flag = flag; 

   // save my place 
    wixData.save('Places', place).then( (newPlace) => { 
       // the search function will refresh my data table. 
        search(); 
    }). **catch** ( (err) => { 
        console.log(err); 
    });      
}). **catch** ( (err) => { 
    console.log(err); 
});  

GOOD LUCK :slight_smile:

Hey,

I had the same issue as well. When I submitted the form, the reference fields (auto-filled items) are blank.

I came across a simple workaround for this. If you have a combination of auto-fill inputs and other user input fields, then use setFieldValue function to submit auto-fill inputs to your database.

This website has an example on how to create an auto-fill form, https://www.vorbly.com/Vorbly-Code/WIX-CODE-AUTO-FILL-FORM-WITH-USER-INPUTS .

Good luck!

Ben

Hi Ohad! Would you be able to give some more details on how to achieve via code?