Question:
How do I apply custom Velo code to all instances of a form on a website?
Product:
Wix Studio.
What are you trying to achieve:
This page, says this:
If you have several elements based on the same form (for example, you copy-pasted a form on the same site), the functions applied to a form ID will run on all elements.
This leads me to believe that I could use the form ID (i.e. 21bcb6c7-02b3-4ed1-b6db-7856094fac03
) to apply code to all instances of a single form. So here is the code I’m trying to apply:
import wixLocationFrontend from 'wix-location-frontend';
if ($w('21bcb6c7-02b3-4ed1-b6db-7856094fac03').rendered) {
$w("21bcb6c7-02b3-4ed1-b6db-7856094fac03").setFieldValues({
fieldValue: wixLocationFrontend.query['UrlParam'],
});
}
What have you already tried:
I’ve asked the question in the Wix Studio Discord chat, in this message. I’ve also tried numerous variations of the form ID; capitalized, removing dashes, with & without the leading # selector, etc.
Additional information:
The form ID is different than the element ID. The element ID would be more like #form1
. Using the element ID only applies to that single element. But the same form could be listed multiple times on a various pages, or even more than once on a single page. So I don’t want to duplicate the code for every instance of the same form.