question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Why does picker.on("change", ...) fire on page load?

See original GitHub issue

Anyone know why picker.on("change", function(color) {...}); fires on page load?

Ideally I would like to only have it fire if the color picker is interacted with but for some reason it fires even if I never use the color picker.

Basic example:

<script>

    var source = document.querySelector('input'),
        picker = new CP(source);

    // prevent showing native color picker panel
    source.onclick = function(e) {
        e.preventDefault();
    };

    picker.on("change", function(color) {
        alert('fire');
        this.source.value = '#' + color;
    });

</script>

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jjrabbitcommented, Mar 14, 2019

Simple is definitely better, it was just an idea.

If it complicates things no sense implementing it.

Thanks!

1reaction
jjrabbitcommented, Mar 11, 2019

Oops I completely missed the documentation on the hooks. I’ll be sure to read more thoroughly before posting an issue next time!

The drag event is closer to what I was looking for but actually start + drag (for example picker.on("start drag", function(color) {...})) is the type of listening I was trying to achieve. Would be cool if you could combine them in a single statement like that but that’s not a big deal.

Your alternative is genius and works great. I’ll just do it that way.

Thanks tovic!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Prevent Onchange triggering on page load
I need to do this way as the errant call onload is preventing my jQuery/Bootstrap datepicker plugins fron initialising on load. With thanks....
Read more >
Prevent unwanted change event when page loads · Issue #149
Happens every time the page is loaded the date input triggers the change event, which makes an unnecesary ajax request because the page...
Read more >
Datepicker - Event does not trigger on fresh page load
On the page where the date picker exists if it is refreshed when the calendar is clicked the popup does not open.
Read more >
[OutSystems UI Web] DatePicker is causing an OnChange ...
I noticed that after implementing the DatePicker widget that my search engine receives requests when the page is loaded. After some investigation I...
Read more >
Fire JS function when people picker completes
You could use some jQuery to identify when the field on the page changes. The DIV for the people picker will have plain...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found