header-logo
Getting started with WixBuild your website and business with Wix. Try using our AI tools to create your website, customize templates, or hire professionals to build or enhance your online presence.
Creating a websiteRead how to use the Wix Editor and manage content on your site. Discover how to protect your visitors' privacy and make your site accessible.
Account & billingReview your account settings, manage your subscriptions and plans and understand your invoices.
Using the Wix mobile appsUse our mobile apps to run your business efficiently on the go and set up a dedicated app for your site members to stay in touch.
Connecting a domainFollow our step-by step guides to learn how to purchase, connect or transfer a domain for your site, and find out how to keep your site’s data secure.
Managing your businessGet tools to grow your business and web presence. Find the right tools for your specific needs, set up online payments and keep track of your site's analytics.
Promoting your siteLearn to make your site more visible promoting it on search engines, sending emails and running paid ads. Improve your online presence with practical tips.
Studio, Partners & EnterpriseGet the most out of your Studio or Enterprise account with advanced features that'll help you work more efficiently.
Need more help?Find solutions for site performance and technical issues, learn about issues we’re working to fix or contact us for help.
placeholder-preview-image
Wix LearnImprove your skills with our courses and tutorials.
Wix BlogGet tips for web design, marketing and more.
SEO Learning HubLearn to increase organic site traffic from search engines.
Website developmentBuild a custom site using our full-stack platform.
Hire a ProfessionalGet matched with a specialist to help you reach your goals.
placeholder-preview-image
In this article
  • Widget API properties
  • Widget API Events
  • Widget API Function
  • Using the Widget API on a Site

Wix Blocks: About the Widget API

In this article
  • Widget API properties
  • Widget API Events
  • Widget API Function
  • Using the Widget API on a Site
Wix Blocks is currently open to a limited number of users.
Use the Widget API to add properties, events, and functions to your widget. Site creators can then access the Widget API properties, events, and functions when editing their site on the Wix Editor or Editor X (learn more about using the API when editing a site)

The $widget object includes:
  • A props object, which contains the properties that you defined, with the values that were set to them by the user of your widget (or the default value that you’ve set in case they were untouched).
  • An onPropsChanged() event registrar, which allows you to register a callback that will be fired when a property value was changed, for example, when the user changes the title:
    $w(‘#myWidget’).title = ’new title’.
  • A fireEvent method, which triggers an event that you defined in the Widget API.

Widget API properties

Properties allow the site owner to access information from your widget. For example, in a shopping widget, you can add properties that represent the products you are selling and the customers. 
Learn more about adding a new property
Learn more about property types

Widget API Events

Add an event when you want to provide information about actions that happen in the widget to the site owner. For example, when a customer adds a product to the cart.

You can use this event in your Blocks app. The site creator that installs your app on a site can also use the event. You can fire your event in the widget's code in Blocks and site creators can see it and register it in the editor.
 

Widget API Function

Add a new function to enable site owners to perform actions related to the widgets on their websites. For example, as a site owner who has a shopping widget, you'd like to be able to get the address of a certain customer through a function and set the address through another function.

Don't forget to document
Make sure to document your widget API by describing any property, event or function you add to it. These descriptions are available to site creators who install your widget. 

Using the Widget API on a Site

When a site creator installs your widget on a site they can control it through the API. 
Want to learn more about Blocks?
Check out the Wix Blocks help articles

Helpmate

Hello

Need a bit more guidance?
Unlock personalized helpLog in to get the most out of Helpmate.