duck.html.components.core.force_update¶
Module containing a class to force update a component, i.e. force generate a patch on event binding. Very useful for components updated using JS.
Usage Example:
# views.py
from duck.html.components.page import Page
from duck.html.components.button import Button
def myview(request):
def on_button_click(btn, *_):
# The following will return update the Button text/innerHTML regardless. Even if it was modified through Javascript.
return ForceUpdate(btn, ["text"]) # Or return a list of ForceUpdates
# Do some page logic
page = Page(request)
btn = Button(text="Some text")
# Add button to page
page.add_to_body(btn)
# Bind btn click, but disable any component update by default.
btn.bind("click", on_button_click, update_self=False, update_targets=[])
# Return page or ComponentResponse
return page
Module Contents¶
Classes¶
Class for applying force updates on HTML components. |
Functions¶
Check if force updates in list are of correct type. |
API¶
- class duck.html.components.core.force_update.ForceUpdate(component: duck.html.components.Component, updates: List[str] = None)[source]¶
Class for applying force updates on HTML components.
Notes:
These updates are only limited to components in the DOM/Component tree.
You cannot add/remove a component from tree with this approach, rather use the default approach.
Initialization
Initialize force update on a component on event.
- Parameters:
component – The HTML component to target.
updates – List of updates to regenerated. These updates are limited to ‘props’, ‘text’, ‘inner_html’, ‘style’, ‘all’.
- __slots__¶
None
- duck.html.components.core.force_update.check_force_updates(updates: List[ForceUpdate])[source]¶
Check if force updates in list are of correct type.