11from datetime import datetime as dt
22
33from pyscript import document
4-
4+ from pyweb import pydom
55tasks = []
66
77
@@ -10,9 +10,12 @@ def q(selector, root=document):
1010
1111
1212# define the task template that will be use to render new templates to the page
13- task_template = q ("#task-template" ).content .querySelector (".task" )
14- task_list = q ("#list-tasks-container" )
15- new_task_content = q ("#new-task-content" )
13+ # Note: We use JS element here because pydom doesn't fully support template
14+ # elements now
15+ task_template = pydom .Element (q ("#task-template" ).content .querySelector (".task" ))
16+
17+ task_list = pydom ["#list-tasks-container" ][0 ]
18+ new_task_content = pydom ["#new-task-content" ][0 ]
1619
1720
1821def add_task (e ):
@@ -33,19 +36,20 @@ def add_task(e):
3336
3437 # add the task element to the page as new node in the list by cloning from a
3538 # template
36- task_html = task_template .cloneNode ( True )
39+ task_html = task_template .clone ( )
3740 task_html .id = task_id
38- task_html_check = q ("input" , root = task_html )
39- task_html_content = q ("p" , root = task_html )
40- task_html_content .textContent = task ["content" ]
41+
42+ task_html_check = task_html .find ("input" )[0 ]
43+ task_html_content = task_html .find ("p" )[0 ]
44+ task_html_content ._js .textContent = task ["content" ]
4145 task_list .append (task_html )
4246
4347 def check_task (evt = None ):
4448 task ["done" ] = not task ["done" ]
4549 task_html_content .classList .toggle ("line-through" , task ["done" ])
4650
4751 new_task_content .value = ""
48- task_html_check .onclick = check_task
52+ task_html_check ._js . onclick = check_task
4953
5054
5155def add_task_event (e ):
0 commit comments