I have 2 collections, 1 is called usuario, the other is called novelas, the novelas collections has a reference field called usuario, obviously reference to the collection with the same name, both collections are generated by users, now, I have this page
here the input elements are connected to the dataset from the novelas collection, in write only (to add a new element) now, this circle selection element in red, it’s where the reference field is, now, I need to put just this element to bring the info based on the current logged in element, so it only shows the elementes that that user created.
why not put the dataset in read and write and ad a filter owner is current logged in? well, because when I did it, and I made a button that linked to this page, it didn’t work because the new user didn’t have something to read to modify
does enyone of you know how can I make this field by current logged in user, just that field.
Funny note: I know nothing about coding
Hi @layonill musset !
Indeed when there are no previous records for a read-write connected dataset, the user input fields that are connected will be disabled.
Since there’s no content to Read you won’t be able to Write .
There are few solutions for that:
-
Two different forms - one for initial submission and the second one for editing and viewing the user
generated content. You can direct the current user to either one by simply using a WixDataQuery that will
check if there’s a previous record (results > 0) and act accordingly.
-
Pre-populate the dropdown - Again, by using a query that matches and returns all the items that are
relevant to a certain user, you can populate the drop down with the desired results of the field you’re
filtering by. Here’s a code example for exactly that:
import wixData from 'wix-data';
$w.onReady(function () {
wixData.query("Usuario")
.find()
.then(res => {
$w("#dropdown1").options = res.items.map(item => {
return {
"label": item.title, "value": item._id
}
})
})
});
Let me know if any of this works for you.
If not, please elaborate on what is exactly that you’re trying to achieve and I’ll do my best to assist.
Doron.
what I need is that dropdown to bring me the element, just the element that the user that is watching that page created, not what others did, because, I solve how to put it in read and wright and make the fields work, using the “new” condition in a button, but I need that dropdown to bring info based on the user that is logged in, because, it shows me what others created, I just want to see what I created, how do I get this?
it is like, filtering the elements in the reference field, based on the owner’s ID, so the user that is looking the info in the moment, can see only the elements in the reference field that he or she created, for example, let’s say in the usuario collection (usuario means user) I created an element called MARK, and some other random user created an item called STEVEN, when I go to the novelas page to input a new novel,a new item in the novelas collection, in the reference dropdawn that contains info it shows me my item called MARK, and the item of other user called STEVEN, I just want to see my item MARK in the dropdown, not other.
@arqly1315 ,
You can use the ID of the user that created the item.
ID is a field that is automatically generated once an item is created.
In this case the wixUsers.currentUser.id will be equal to the Owner of the item (the person who created it).
Query the ID of the current user and search for a record with an equal value.
Return the relevant items and populate the dropdown with them.
Let me know if it works for you.
Doron.