Wix has long been lauded for its intuitive drag-and-drop interface, making website creation accessible to everyone. But for businesses and developers seeking deeper customization, dynamic data interactions, and seamless third-party integrations, Velo by Wix (formerly Corvid) is the game-changer. Velo empowers you to add custom JavaScript, interact with databases, and integrate APIs directly within your Wix environment, transforming a simple website into a powerful web application.
However, harnessing Velo's full potential often requires delving into code, and finding practical, problem-solving examples can be a significant hurdle. As digital engineering experts at 'Do Digitals', we understand this challenge. This post provides highly technical, real-world Wix Velo examples to help you overcome common development obstacles and elevate your Wix site to new heights.
Problem: You need to display a large collection of items (e.g., properties, job listings, products) with advanced filtering and pagination, which Wix's default repeaters can't handle efficiently or robustly.
Velo Solution: Use Velo to query your Wix database collections, dynamically render content, and implement sophisticated filtering logic client-side or server-side.
import wixData from 'wix-data';
$w.onReady(function () {
// Populate initial repeater
loadItems();
// Event listener for filter changes
$w('#filterDropdown').onChange(() => loadItems());
});
function loadItems() {
let query = wixData.query('YourCollection');
const selectedFilter = $w('#filterDropdown').value;
if (selectedFilter !== 'All') {
query = query.eq('category', selectedFilter);
}
query.find()
.then(results => {
$w('#repeater1').data = results.items;
// Connect repeater elements to data fields
$w('#repeater1').onItemReady(($item, itemData, index) => {
$item('#textTitle').text = itemData.title;
$item('#imageItem').src = itemData.mainImage;
});
})
.catch(error => console.log(error));
};
Problem: Your forms require complex validation rules (e.g., conditional fields based on previous input, custom regex patterns, real-time feedback) beyond Wix's basic built-in options.
Velo Solution: Implement custom validation functions and event handlers to ensure data integrity and a superior user experience.
$w.onReady(function () {
$w('#inputEmail').onCustomValidation((value, reject) => {
const emailRegex = /^\S+@\S+\.\S+$/;
if (!emailRegex.test(value)) {
reject('Please enter a valid email address.');
}
});
$w('#dropdownService').onChange((event) => {
if (event.target.value === 'Custom') {
$w('#textBoxCustomDetails').show();
$w('#textBoxCustomDetails').required = true;
} else {
$w('#textBoxCustomDetails').hide();
$w('#textBoxCustomDetails').required = false;
}
});
$w('#buttonSubmit').onClick(() => {
if ($w('#form1').valid) {
// Submit data or call backend function
console.log('Form is valid and ready to submit!');
} else {
console.log('Please correct the form errors.');
}
});
});
Problem: You need to connect your Wix site with external services (e.g., CRM, payment gateways, weather APIs) but require secure handling of API keys and server-side logic.
Velo Solution: Utilize Velo's backend web modules (`.jsw` files) to make HTTP calls to external APIs, keeping sensitive information secure and off the client-side.
http-functions.jsw or a custom web module like apiIntegrator.jsw):import { fetch } from 'wix-fetch';
export async function callExternalApi(endpoint, data) {
const apiKey = 'YOUR_SECURE_API_KEY'; // Stored securely, e.g., in Secrets Manager
const response = await fetch(`https://api.example.com/${endpoint}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${apiKey}`
},
body: JSON.stringify(data)
});
if (response.ok) {
return response.json();
} else {
throw new Error(`API call failed: ${response.status} ${response.statusText}`);
}
}
import { callExternalApi } from 'backend/apiIntegrator';
$w.onReady(function () {
$w('#buttonSend').onClick(async () => {
const dataToSend = { name: $w('#inputName').value, email: $w('#inputEmail').value };
try {
const result = await callExternalApi('submit-lead', dataToSend);
console.log('API Response:', result);
$w('#textMessage').text = 'Data sent successfully!';
} catch (error) {
console.error('Error sending data:', error);
$w('#textMessage').text = 'Failed to send data.';
}
});
});
Problem: You need to create personalized user experiences where content or functionalities are visible only to specific user roles or individual members, beyond Wix's basic member area permissions.
Velo Solution: Implement custom logic to determine user roles and dynamically control element visibility or redirect users based on their authenticated status and custom roles.
import wixUsers from 'wix-users';
import wixLocation from 'wix-location';
$w.onReady(async function () {
if (wixUsers.currentUser.loggedIn) {
let user = await wixUsers.currentUser.getRoles();
if (user.roles.some(role => role.name === 'Admin')) {
$w('#adminPanel').show();
} else if (user.roles.some(role => role.name === 'Premium Member')) {
$w('#premiumContent').show();
} else {
$w('#basicContent').show();
}
} else {
// Redirect unauthenticated users or show login prompt
wixLocation.to('/login');
}
});
Navigating the intricate world of Wix Velo can be challenging, but the possibilities for advanced web functionality are limitless. At 'Do Digitals', we specialize in transforming complex requirements into robust, high-performing custom Wix Velo solutions tailored precisely to your business needs.
Don't let technical hurdles limit your vision. Our expert digital engineers are ready to build the exact custom features discussed here and more, pushing the boundaries of what your Wix site can achieve. Hire us right now to unlock the full potential of your online presence!
Website: dodigitals.org
Call / WhatsApp: +919521496366
Let's discuss your digital transformation.