Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select doesn't properly support onchange event. #11

Open
SENTINELITE opened this issue Jul 1, 2023 · 3 comments
Open

Select doesn't properly support onchange event. #11

SENTINELITE opened this issue Jul 1, 2023 · 3 comments

Comments

@SENTINELITE
Copy link

I was perusing this as a potential overhaul for my PI, but I currently use the onchange="funcXYZ(this.value)" to react to changes when a new selection is made.

I can't seem to get it to work?

@GeekyEggo
Copy link
Owner

GeekyEggo commented Jul 3, 2023

Hey @SENTINELITE, thanks for expressing interest in the components.

Each component currently exposes a custom valuechange event which is invoked when any of the following occur:

  • When the value first loads in the PI, i.e. the component reads the settings and populates the component.
  • When the value is changed by the user.
  • When the value is changed due to the PI receiving didReceiveSettings, i.e. the plugin changed the settings and the PI is synchronizing.

Here is a usage example.

<!DOCTYPE html>
<html>

<head lang="en-gb">
    <meta charset="utf-8" />
    <script src="https://cdn.jsdelivr.net/gh/geekyeggo/sdpi-components@v2/dist/sdpi-components.js"></script>
</head>

<body>
    <sdpi-item label="Select">
        <sdpi-select>
            <option value="1">One</option>
            <option value="2">Two</option>
            <option value="3">Three</option>
        </sdpi-select>
    </sdpi-item>

    <script type="text/javascript">
        document.querySelector("sdpi-select").addEventListener('valuechange', function (ev) {
            console.log(ev.target.value); // 1, 2, or 3
        });
    </script>
</body>

</html>

Please let me know if you have questions, and any feedback is appreciated.

@GeekyEggo
Copy link
Owner

I've also noticed that this event isn't documented anywhere on https://sdpi-components.dev, so I'll be sure to make a note to get that updated. 👍

@SENTINELITE
Copy link
Author

Awesome, thanks for pointing that out, Geeky! I'll give it a go next week!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants