lona-web-org / lona

Write responsive web apps in full python
MIT License
527 stars 27 forks source link

Attribute `checked` doesn't work #71

Closed maratori closed 3 years ago

maratori commented 3 years ago

Following view doesn't work

class CheckedAttributeBugView(LonaView):
    def handle_request(self, request):
        self.html = HTML(
            '<input type="radio" checked>',
            '<input type="checkbox" checked>',
            Node(tag_name='input', type="radio"),
            CheckBox(),
            Button('check all', handle_click=self.check_all),
            Button('uncheck all', handle_click=self.uncheck_all),
        )
        return self.html

    def check_all(self, event):
        for node in self.html.query_selector_all('input'):
            node.attributes['checked'] = ''
        self.show()

    def uncheck_all(self, event):
        for node in self.html.query_selector_all('input'):
            del node.attributes['checked']
        self.show()
  1. First 2 inputs should be checked (selected) on load page -> they don't
  2. Button check all should select all 4 inputs -> nothing happens
  3. User selects manually (in browser) all 4 inputs then presses button uncheck all -> nothing happens

Root cause

As far as I understand it doesn't work because of this javascript https://github.com/lona-web-org/lona/blob/497dd940aa9bcac6e761307f89920303b26e9955/lona/client/dom-renderer.js#L50-L51

and

https://github.com/lona-web-org/lona/blob/497dd940aa9bcac6e761307f89920303b26e9955/lona/client/dom-updater.js#L444-L445

fscherf commented 3 years ago

@maratori Ack! That's a bug. I created a pr to fix it. We need testing for the node rendering code. I currently research how to build a test-suite using aiohttp and selenium.

Btw: You don't have to call self.show() from a callback. When Lona runs an input event handler that is not handle_request() it looks for changes in the last shown HTML tree. If the tree is changed self.show() gets called automatically.

maratori commented 3 years ago

Btw: You don't have to call self.show() from a callback. When Lona runs an input event handler that is not handle_request() it looks for changes in the last shown HTML tree. If the tree is changed self.show() gets called automatically.

Didn't know, thanks!

I currently research how to build a test-suite using aiohttp and selenium.

I have some experience with selenium tests. There are great tools for that:

fscherf commented 3 years ago

@maratori

I have some experience with selenium tests

\o/ That's what i wanted to hear :D lets discuss that in #74. I hope we can close this issue here today, i expect the testing discussion will be longer