Why does picker.on("change", ...) fire on page load?
See original GitHub issueAnyone 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:
- Created 5 years ago
- Reactions:1
- Comments:6 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Simple is definitely better, it was just an idea.
If it complicates things no sense implementing it.
Thanks!
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 actuallystart
+drag
(for examplepicker.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!