Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How do I use IDOM to preventDefault? #356

Answered by rmorshea
Archmonger asked this question in Question
Discussion options

Does IDOM override href's click events to intercept URL routing, or will I need to manually implement this for SPA purposes?

If so, is it a generic selection across all href elements, or only on href components directly rendered by IDOM?

You must be logged in to vote

Instead of just assigning a plain function to an event like onClick you can add a decorator to the event handler that encodes extra information like prevent_default or stop_propagation.

@idom.component
def MyComponent():
 @idom.event(prevent_default=True)
 def handle_click(event):
 ...
 return idom.html.href({"onClick": handle_click}, ...)

Replies: 1 comment

Comment options

Instead of just assigning a plain function to an event like onClick you can add a decorator to the event handler that encodes extra information like prevent_default or stop_propagation.

@idom.component
def MyComponent():
 @idom.event(prevent_default=True)
 def handle_click(event):
 ...
 return idom.html.href({"onClick": handle_click}, ...)
You must be logged in to vote
0 replies
Answer selected by rmorshea
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /