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.

Option to prevent default in domSource.select().events()

See original GitHub issue

Cycle allows turning virtually any DOM event into a stream to be consumed by intents. However, for some events this proves pointless as the event’s default handling is disruptive.

For example, suppose I have a form and would like to receive a stream of submissions on it, I could do something such as:

Cycle.h('form#search', {onsubmit: 'searchSubmits$'}, [
  Cycle.h('input#q', {autocomplete: 'off', name: 'query', type: 'text', placeholder: 'Add term'})
])

While this would indeed create a stream, the form would still actually navigate to its target upon submission, thus denying me the ability to make sensible use of the stream.

What I would like to have (and will gladly make a reality) is something like this:

Cycle.h('form#search', {onsubmit: 'searchSubmits$!'}, [
  Cycle.h('input#q', {autocomplete: 'off', name: 'query', type: 'text', placeholder: 'Add term'})
])

Which will basically retain the same behavior, except it will also call preventDefault for the submit event, allowing use of the stream.

I am, of course, entirely open to suggestions on how to actually signify this behavior. Being a Ruby buff I am all for adding bangs to the end of things to signify anything drastic, but this is not necessarily the best way.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:25 (23 by maintainers)

github_iconTop GitHub Comments

4reactions
Widdershincommented, Mar 7, 2017

Why don’t we make it an optional argument to events? DOM.select('.add').events('click', {preventDefault: true})

2reactions
Widdershincommented, Apr 24, 2017

Sure thing @grozen, have a go. I will review your pull request and help you get it merged. 🙂 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Event.preventDefault() - Web APIs | MDN
The preventDefault() method of the Event interface tells the user agent that if the event does not get explicitly handled, its default ...
Read more >
preventDefault() Event Method - W3Schools
The preventDefault() method cancels the event if it is cancelable, meaning that the default action that belongs to the event will not occur....
Read more >
API reference (dom) - Cycle
preventDefault is by default false , and indicates to the driver whether event.preventDefault() should be invoked. This option can be configured in three ......
Read more >
preventDefault() not working on a particular option select
The preventDefault() call only stops the current change event handler. The one you've assigned via the onchange attribute will still run ...
Read more >
How to correctly use preventDefault(), stopPropagation(), or ...
preventDefault() , event.stopPropagation() and return false; . So today we're going to learn what the differences are between the three, and ...
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