[solved] How to connect ID field to Input?

Hi guys. I can’t connect the ID field of my database to the Input. Any idea what the problem is?

1 Like

https://support.wix.com/en/article/working-with-user-input-elements-9560341
https://support.wix.com/en/article/creating-a-form-with-user-input-elements

HI, givemeawhisky. Thanks for the answer, but it does not solve my problem. The first link you sent me says “Input boxes can connect to text and number fields.” As you can see in my screenshot, the ID field is of type “Text”, but I cannot connect it. That’s my problem.

@andrew-kov You can’t connect the ID field to a user input box, even if the dataset is set to “Read Only” (needless to say that you can’t rewrite an ID, as this field is created internally by WIX).
If you want the input box to display to ID, you shoudl push it by code:

$w("#input2").value = item.id;

Where item.id is the ID you retrieved using collection query.

@jonatandor35 Hi. Thanks for the help. I’m not a coder, but I’m trying. I tried to do something with the code you gave me, but it does not work for me. Please can you give me a little more detailed instructions.

@andrew-kov sure, but you should provide more details first, For example, you want to display an ID in a text input box.
Can I assume that this dataset is filtered and therefore contains only 1 record (which you want to display)? Or maybe you put this input box in a repeater and you want each repeater item to display another ID?

@jonatandor35 Yes, I forgot to say, I use a repeater. I want each repeater item to display another ID.

@andrew-kov so in that case, connect the repeater to the dataset via the editor, (the dataset has to be in a read-only state) and use this code:

$w.onReady(function () {
$w("#repeater1").onItemReady( ($item, itemData, index) => {
  $item("#input2").value = itemData._id;
});
})

Make sure the property names fit.

@jonatandor35 Ok. Thanks a lot. But I have one more question. What if I want to realize this on a dynamic page? I have a Text Input on a dynamic page and I want to connect the ID field to a Text Input.

@andrew-kov the same (unless I didn’t get your intention)

@jonatandor35 Sorry, I should have given you more details. I tried to use your code with a Repeater and it works great, but now I have a slightly different issue. Now I need to do the same but on a dynamic page without a Repeater. I just have a Text Input on the dynamic page and I want to connect it to the ID field in my database. I tried to costamize your code for this, but I am not a coder, so I could not.

@andrew-kov ,

$w.onReady(function () {
const currentItem = $w("#datasetName").getCurrentItem();
$w("#input2").value = currentItem._id;
})

@jonatandor35 Thank you so much. You saved me again. It works perfectly on dynamic pages, but I have one last question. How can I do the same thing in the lightbox. I have a Text Input in my lightbox and I need to connect it to the ID field. I tried to use the last code you sent me, but it does not work in the lightbox.

@andrew-kov if it’s a lightbox that gets open from the dynamic page, o you should get the id on the page and pass it to the lightbox.
See here: https://www.wix.com/corvid/reference/wix-window.html#openLightbox
and here: https://www.wix.com/corvid/reference/wix-window.lightbox.html#getContext

If it doesn’t work for you, let me know, and I’ll try to help tomorrow.

@jonatandor35 No, lightbox gets open not from a dynamic page. It is a regular page.

@andrew-kov again some details are missing. Is it a lightbox that gets open when you click on a repeater item? Is the data-set filtered to contain only 1 item?

@jonatandor35 Yes, I use a repeater. When the user clicks on a button in the repeater, it opens a lightbox that contains dynamic data (images and text).

@andrew-kov How does your lightbox contain the dynamic data? Do you pass the data from the repeater item to the light box or do you have a different light-box for each repeater item?

https://support.wix.com/en/article/working-with-user-input-elements-9560341 best answer!

@jonatandor35 Hi. I solved my problem. I’d like to thank you again. You’ve been very helpful.