
Welcome back to Wix Ideas! Today, we're diving into how to populate interactive elements on your Wix website using Velo. We'll cover how to dynamically fill elements such as dropdowns, checkbox groups, and selection tags with values from your collections, ensuring no duplicate values.
Populating these elements directly from a collection not only saves time but also ensures consistency and accuracy. Whether you're running a restaurant, an online store, or any other business, this method will streamline your content management process.
Step 1: Understanding the Elements š§©
First, letās take a look at the elements:
Dropdown: You can add choices by clicking on "manage choices" and edit or duplicate options. Adding multiple choices at once is straightforward.
Checkbox Group: Similar to dropdown, you manage choices the same way.
Selection Tags: Manage choices here too, although adding multiple choices at a time isn't available directly.
Our goal is to populate these options directly from a collection without manually adding them.
Step 2: Setting Up the Collection š
To begin, ensure you have a collection set up in your Wix site. If you donāt know how to create a collection, check out our previous post on understanding content management systems. This comprehensive guide covers everything from creating a collection to displaying data to your users and adding data to your collection.
Hereās a sample collection for our tutorial:
Cuisine Type: Lists various cuisines offered by the restaurant.
Dietary Preferences: Lists different dietary preferences.
Tags: Lists tags describing specials or popular items.
Step 3: Writing the Function š»
Next, letās create a function to populate these elements. This function will be a parametric one, which means it can take parameters to customize its behavior.
Hereās the basic code structure:
Explanation:
wixData.query(collectionID): Queries the specified collection.
.limit(1000): Limits the number of items pulled in.
.ascending(fieldID): Orders the items in ascending order.
.distinct(fieldID): Ensures no duplicate values.
.then((results) => {...}): Handles the results, mapping them into an array of objects with labelĀ and value.
Step 4: Using the Function š ļø
To use this function for different elements, you just need to call it with appropriate parameters. For example:
Step 5: Ensuring No Duplicates š
The distinctĀ method ensures that even if there are duplicate values in your collection, only unique values will be populated in your elements.
Step 6: Testing and Finalizing ā
Before publishing, test your site to ensure everything works as expected. Preview your site, and you should see your elements populated with unique values from your collection.
Conclusion š
This method of populating interactive elements dynamically from your collection saves time and ensures consistency across your Wix site. If this tutorial was helpful, please leave a comment and don't forget to subscribe. Your support helps us create more content like this and reach Wix users around the world.
Thank you for reading, and happy coding! š
Code
Leave a comment (0)
Thanks for leaving a commentš

ahmed
May 19, 2024
wix form data
Hi i need your help also in wix form submission
the problem is that some fields are generated when $w.onReady(function () { like day & date and when i choose the student name i get the phone number from database .
and the form save only the field u fill it by ur self like input or dropdown
Reply

Walter Odibi
January 20, 2000

bromar
Sep 29, 2023
Love the tutorial!!!
You are truly great at creating these instructional videos!! Thank you! I am having trouble figuring out . . 'the triggered email' . . it is not being sent to the user submitting the form, the form and the email to the admin works great. . Could you point me to where this might have already been addressed? or any other help? On a second note. .the submit button success/failure message will go back to the default message once it's connected to the data set(I couldn't figure that out either. )
Reply

Walter Odibi
January 20, 2000

kaan
Jun 4, 2023
wishlist and rating system
hello sir I try today 2 hours but not working if you want I pay money can you do this 2 ( wishlist and rating star) system please I send to you invaid
Reply

Walter Odibi
January 20, 2000
Hi there, you can contact me here using the in-app chatbox

Waqas
Apr 16, 2023
Triggered Email Backend
Hi mate please can you send email by backend
Reply

Walter Odibi
January 20, 2000
Hi Waqas, there isn't a backend code for this tutorial. The emails will be sent from the client-side.

Ghan
Dec 29, 2022
Great Tutorial
Hi !
First of all, I want to thank you for your great tutorials, they helped us a lot with the coding.
But I still need your help, if you don't mind. I have based on Save Calculated Field using Wix Data Hooks Codes, to code my form . but the problem is I don't know why the code only reads the computation for "week2" computation and not the "weeks"
here is the code
I also did a separate column in the dataset where the chosen datas for both fields will be placed.
$w.onReady (() => {
$w("#Person").onChange(() => {
$w("#weeks").onChange(() => {
$w("#week2").onChange(() => {
let person = Number($w("#Person").value);
let weeks = Number($w("#weeks").value);
let week2 = Number($w("#week2").value);
$w("#totalLabel").show();
$w("#totalLabel").text = `"${String(weeks * Number(person))}ķģ"`; //DESIGN YOUR MESSAGE
$w("#totalLabel").text = `"${String(week2 * Number(person))}ķģ"`; //DESIGN YOUR MESSAGE
});
});
});
});
Reply

Walter Odibi
January 20, 2000
Hi there, thanks for your comment. I see why this is a problem. The onChange() function seems wrong in combination.
To combine onChangeFunctions use this method
$w("#Person, #weeks, #weeks2").onChange(() => {
//code here
});

Walter
Aug 8, 2022
More Details? Watch video
Hi, you can click here to watch the video https://www.youtube.com/watch?v=9bx7-nBeZ5c
Reply

Walter Odibi
January 20, 2000

Walter
Jul 11, 2022
For you
šŗ WATCH THE VIDEO https://www.youtube.com/watch?v=AgPJEU8wpp0
Reply

Walter Odibi
January 20, 2000

Walter Odibi
Apr 18, 2022
Awesome Feature
This tutorial shows you how to display views on your Wix repeater.
šŗWATCH VIDEO HERE https://www.youtube.com/watch?v=Iz7SdaCSdXg
Reply

Walter Odibi
January 20, 2000

Walter Odibi
Apr 18, 2022
Amazing tutorial
This amazing tutorial will show you how to a comment section to your WIX dynamic page.
šŗWATCH VIDEO HERE https://www.youtube.com/watch?v=f8-vJQFNZ_c
Reply

Walter Odibi
January 20, 2000

Walter Odibi
Apr 10, 2022
Great Featureš
This amazing tutorial will show you how to add a visitor view counter to your WIX dynamic page.
š©MORE TUTORIALS https://www.wixgenius.com/wix-tutorials
Reply

Walter Odibi
January 20, 2000