Skip to content

Commit

Permalink
docs(custom_js): add more comment to code example
Browse files Browse the repository at this point in the history
  • Loading branch information
jourdain committed Jan 17, 2024
1 parent 85795e2 commit 38de8e6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
Empty file.
11 changes: 9 additions & 2 deletions examples/09_advanced/custom_js/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,33 @@ def load_my_js(server):
js_file = Path(__file__).with_name("my_utils.js").resolve()
server.enable_module(
dict(
serve={"my_code": str(js_file.parent)}, scripts=[f"my_code/{js_file.name}"]
# Path to serve under /my_code
serve={"my_code": str(js_file.parent)},
# JS file(s) to load
scripts=[f"my_code/{js_file.name}"],
)
)


class CustomAddOnJS:
def __init__(self, server=None, table_size=10):
self.server = get_server(server, client_type="vue3")
load_my_js(self.server)
self.ui = self._build_ui()

# Make sure my js code get loaded on the client side
load_my_js(self.server)

def _build_ui(self):
with SinglePageLayout(self.server, full_height=True) as layout:
with layout.content:
vuetify3.VTextField(
v_model=("text_1", "1.2"),
# Use our extended trame.utils in template definition
rules=("[utils.my_code.rules.number]",),
)
vuetify3.VTextField(
v_model=("text_2", "2"),
# Use our extended trame.utils in template definition
rules=("[utils.my_code.rules.int]",),
)

Expand Down
2 changes: 2 additions & 0 deletions examples/09_advanced/custom_js/my_utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// global trame.utils can be extended by users
// - within template definition, it can be accessed as "utils.my_code.rules.int"
window.trame.utils.my_code = {
rules: {
number(v) {
Expand Down

0 comments on commit 38de8e6

Please sign in to comment.