I store options for input elements in a collection field.
In my custom code, I fetch and populate inputs with the options.
For displaying the saved data I also fetch the values with the same piece of code.
And I have a strong feeling that I am doing something wrong, or, at least not elegant and efficient.
When displaying data in a repeater I fetch display options for each repeater item. It is delaying their display.
For input elements, fetching and populating options also causes some issues due to the async nature of fetch: https://www.wix.com/velo/forum/community-discussion/problem-with-loading-options-to-radiobuttons-in-update-form
The question is: what is the right way to do such things?
Should I first load all the options from the server and store them in session and only after that fill the inputs and set their default values to avoid issues with async?
For displaying data in repeater: should I pack all the needed data in JSON on server and pass it to repeater in order not to fetch value for each field separately?
Another thing that confuses me: I can`t understand which code is running on server and which code is running on client.
I got used to that the server code is PHP or JAVA and the client code is JS. In Wix, all code is JS.
If I am writing code on a page is it all loaded and running on client? Is it ok to write collection queries on pages? Or it is better to put all the queries and main (server-side) logic into the “Packages (npm)” section?
The client code will be found in the page code and public files. Server side will be in the backend. You can start out with Velo: Where Do I Put My Code? for an explanation. The Wix Velo backend is based on nodeJS, for which you can find a ton of material by doing an Internet search.
I would suggest reviewing the Velo Basics . and working your way through the rest of the documentation.
Don’t worry - it’s really not all that complicated.
If you’re having difficulties getting something to work, you can share your code here (in a code block) for comments. Explain what you’re trying to do, what’s working (or what you think is working), and what isn’t.
Here’s an example that demonstrates how to populate a dropdown without duplicates .
I dare say that I am already familiar with some Velo basics.
I wrote my first hook and reported two Velo bugs ( [1] , [2] )
And it is nothing wrong with my code, it works.
What I am seeking is advice about architecture or best-practices for the cases I described above.
@oshulyak Well, you were saying that your code had delays, and you wanted to know how to do things better. The example I linked to do does something similar, but I don’t detect any delays.
Perhaps share sections of your code that you’re interested in so you can get some opinions and suggestions on how you might be able to improve.
The delay happens when displaying data in a repeater because when the repeater item is ready, I have only an English value that is stored in the collection ( value of the drop-down option). And after that, I have to load a Russian text for that value from another collection ( label of the drop-down option) with a separate request. And it works as expected. Maybe I just need to get rid of that extra-request somehow.
And there is another problem with updating data in a form described here