Getting value from custom element?

I have a custom element with a group of checkboxes in it. I was wondering how i would get the value of the checkboxes (which ones are checked) on my main page file?

I have used the Dropdown Custom Element example to get data into the custom element but how do i get it out? Am i missing something?

On the page use .on() and on the custom element use .dispatchEvent()
See here:
https://www.wix.com/corvid/reference/$w/customelement/on

Thanks that works! :grinning:

You’re welcome :slight_smile:

How to get value from an input inside a Custom Element, without an Event being triggered inside the custom element?
For example, I want to read the value of an input inside the custom element, after clicking a button outside of the custom element.

So the you need two-sided communication.

OUTSIDE:
You need 2 things:

  1. a button onClick handler that uses setAttribute to change an attribute value of the custom element in accordance to the value you wish to pass. For example you can set a attribute named clickcounter and assign it incrementing value on click.

  2. An .on() to detect the returned value
    INSIDE THE CUSTOM ELEMENT

  3. You need to add an attributeChangedCallback to detect the change, and once you detect :

  4. Use dispatchEvent to pass a value back to the outside.

See:
https://www.wix.com/corvid/reference/$w/customelement

@jonatandor35 that’s cool but what if I need to use setattribute when the page is loading ?