HTML id attribute for components

A beautifully neat solution from @stucork

Override the base Component class in the startup form/module:

from anvil import Component
from anvil.js import get_dom_node

def set_id(self, value):
    get_dom_node(self).id = value

def get_id(self):
    return get_dom_node(self).id

Component.id = property(get_id, set_id)

Much nicer than the slightly revolting set_id function I’ve been using for years!

6 Likes