You can now add multiple items to Reference Field Type

It’s hard to deduce how you ended up in this situation, or what that situation even is. Either way, whenever you do field properties changes, don’t wait to long until you publish your site, because if you accidentally reload the site, field properties changes will be lost, but the actual data store won’t. This seems to be the case of yours.

@jeff-haskins , you can. Try query referenced method.

@adas-bradauskas What do You mean by “accidentally reload the site”? Sandbox? Live?
Please example

Hello fellow Wixers,

I’m trying to have people enter data into a multi-item reference field of a collection using a selection box input. However, I can’t seem to be able to connect that selection box to the multi-reference field of my collection.

To take the movies-actors analogy, I am trying to have people enter details of a movie and use multiple selection to select the actors who appear in the movie. I have a dataset linked to the movie collection on the page, and that collection contains a multi-reference field mirrored in the actors collection. How can I link the selection box to offer the list of actors in the actors collection so that people can select all the actor who appear in the movie, and then hit a submit button that will fill data in the movie collection with the details provided, along with the multiple selection of actors?

Any hint would be much appreciated

Hey Nicolas,

I’m afraid but you won’t be able to do it without code. For this to work, you’d need to use special method for multiple item reference includeReference() .

@adas-bradauskas Hi Adas, I’ve tried both the include() method and the query referenced method to no avail… Can you please help me? I’m really struggling here.

This is what I have currently that isn’t working:

import wixData from ‘wix-data’;

$w.onReady( function () {
$w(“#searchedrep”).onItemReady(($item, itemData, index) => {
$item(“event”).text = itemData.relatedjob;
$item(“#description”).html = itemData.jobdescription.substring(0, 225) + ‘…’;
$item(“#thumbnail”).src = itemData.thumbnail;
$item(“#thumbnail”).link = itemData[‘link-EventPhotos-relatedjob’];
$w(“#thumbnail”).clickAction = “link”;
})
});

export function searchbutton_click_1(event) {
wixData.query(“EventPhotos”)
.include(“categories”)
.contains(“relatedjob”, $w(“#searchbox”).value)
.or(wixData.query(“EventPhotos”)
.contains(“jobdescription”, $w(“#searchbox”).value))
.or(wixData.query(“EventPhotos”)
.contains(“categories”, $w(“#searchbox”).value))
.or(wixData.query(“EventPhotos”)
.contains(“tags”, $w(“#searchbox”).value))

    .find() 
    .then((results) => { 
        $w("#searchedrep").data = results.items; 
        $w("#searchedrep").expand(); 
    }); 

}

@elena , hey! It seems that you’re using include() method which works only with single item reference field. Instead, you should use queryReferenced() .

@adas-bradauskas Hi, thank you for responding! I’ve tried using the queryReferenced method - I’m sure I’m not doing it properly… Could you please show me an example if you know of one? What I really want is for users to be able to enter text to run a query on ALL fields of a data set, including multiple reference fields… Do you know if that’s even possible? I’m struggling because it seems like it should be so simple, but it really isn’t… Thank you!!

It seems like Wix is very close to having an input solution with the User Input Object “Multiple Selections”, however it only works with field type “Tags”. Unfortunately “Tags” do not offer the same filtering options as references. It doesn’t seem like a far leap to adapt the Multiple Selection object to attach to a Multi-Item Reference field. PLEASE?

Yes we need something! It would also be great to have a search bar or dropdown type element that is similar to the multiple reference field input in the database.

Hi there… so using the Movies and Actors analogy… I have a database with movies (and a separate one with actors). Now I want to add the actors to the movie using a multi-items reference field. How do I do that on a form? I can add the actors, but how do I connect them to the movie? This is the part that I am missing.

Hey Eric,

This would require some code. So if you’re build a form for a new actor, you’d need to have a dropdown field for movies. In the Connect Panel of that dropdown, toggle to make dropdown options connectable to another dataset and then connect those dropdown options to Movies collection. Make sure Dropdown value part is not connected.

Mind that you’d connect your dropdown options to Movies Title or similar human readable field, but the true unique identifier for the Movies is _id field.

Then, you need the following logic:

  1. Register onChange() handler and when it fires, based on title value, do wixData.query() to get item’s _id.

  2. Register onClick() handler on submit button (this button should not be connected to dataset) and when it fires, collect values from all other input fields, do wixData.insert() to submit the actor, and in the promise run wixData.insertReferenced() to submit the movie.
    Mind that we don’t currently have a multi value dropdown component, so if you want to submit multiple movies with single actor, you’d need to figure out a creative way with either using multiple checkboxes, repeater or something else. Essentially, you’ll be storing list of Movies and pass them to wixData.insertReferenced() when you submit Actor.

Hope that helps you to get started!

@adas-bradauskas Thank you so much for your feedback! Do you have any code that I can reference in this example?

@adas-bradauskas Hello Adas, So sorry to burden you. Do you have any sample code to get me going with this request? I also think this would be a helpful article to put as a wix reference page as well. As I am sure other users may have the same question.

@_eric Unfortunately, I don’t, but I’ll let the others know it would be a useful article.

@adas-bradauskas This would be a useful article! Please let us know if you end up writing

Hi
I have 3 collections i am creating reference fields in one collection from taken other 2 collections in fields .how can i submit form reference fields in a collection using code .but i am trying to insert reference method but it’s not working. i didn’t get any idea how to do.if you have any examples please send me.thank you.

please give me any suggestions above query

  1. Hi everyone

  2. I have 3 collections one is Showcast collection and another People & CastRoles collections.i am creating reference fields in showcast collection from those reference fields are one peoples collection in person id and CastRoles collection in Role id.

=>Design part is find out below screen shot

  1. This is showcast collection in creating reference fields.


=> This is Peoples collection


=> This is CastRoles collection

  1. => i am using below code adding reference filed’s :

  2. $w(‘#submit’).onClick(() => {
    let a = $w(‘#RolsSelection’).value;
    let b = $w(‘#Person’).value;
    let c = $w(‘#ShowId’).value;

wixData.aggregate(‘ShowCasts’)
.group(‘title’)
.avg(‘title’).descending(‘title’)
.run()
.then((res) => {
let item = res.items[0];
maxid = item._id;
console.info (maxid);
maxid++;
$w(“#showcastdataset”).setFieldValue(“title”, maxid);
$w(‘#showcastdataset’).setFieldValue(‘roleId’, (a));
$w(‘#showcastdataset’).setFieldValue(‘personId’, (b));
$w(‘#showcastdataset’).setFieldValue(‘showId’, (c));;
$w(‘#showcastdataset’).save();
})
//submit.onclick
})
}))
$w(‘#showcastdataset’).save();;
$w(‘#showcastdataset’).save();
})
//submit.onclick
})
}))
});
$w(‘#showcastdataset’).save();
})
//submit.onclick
})
}))
//submit.onclick;
$w(‘#showcastdataset’).save();
})
//submit.onclick
})
}))
});
$w(‘#showcastdataset’).save();
})
//submit.onclick
})
}))
});
$w(‘#showcastdataset’).save();
})
//submit.onclick
})
}))

=> according to above code output like this way.please check the below screenshot.

  1. But i don’t want to like above output ,no need to [reference is broken ] i want to adding the number only.

  2. i) I try to find out the solution using below code please check these 2 screenshots:

  1. =>according to above code ,i got output output like this find out below screen shot


ii) I tried on Another way using this below code:but it’s not working.

=> Finally i want to like this way of OUTPUT in below screen shot .please give me any suggestions (or) send me if you have any examples.i hope i am getting a positive response form your’s.Thanks for your valuable time spending on above issue.

Thanks & Regards
koteswararao

Hi everyone

I have 3 collections one is Showcast collection and another People & CastRoles collections.

  1. i am creating reference fields in showcast collection .how to submit form with two reference fields.expect showid textbox remaining 2 user inputs reference fields.those three user inputs conncets to showcast dataset .but reference fields are not visible to conncets to daatset its not possible how to solve this issue.i am trying insert reference [ https://www.wix.com/corvid/reference/wix-data.html#insertReference ] i am getting error is “reference is broken”.


Thank you…
please give me any suggestion or coding snippits [wix corvid reference].