reflex icon indicating copy to clipboard operation
reflex copied to clipboard

Improve either checkbox API or documentation.

Open Lendemor opened this issue 2 years ago β€’ 2 comments

Describe the bug If I have 2 checkboxes using the same Var State.opened, checking one should check the other, but it is currently not the case.

(I used 2 checkboxes as an example, but if a different event handler change State.opened, the checkboxes is also not updated)

To Reproduce

class State(pc.State):
     opened: bool = False

def index():
    return pc.center(
        pc.checkbox(State.opened, on_change=State.set_opened),
        pc.checkbox(State.opened, on_change=State.set_opened),
    )

app = pc.App(state=State)
app.add_page(index)
app.compile()

Expected behavior Checkboxes using same variable should always display same values.

Screenshots

image only one is checked, but both should be.

Specifics:

  • Python Version: 3.10
  • Pynecone Version: 0.1.14

Lendemor avatar Feb 04 '23 18:02 Lendemor

I don't think this is a bug - you need to bind a is_checked to the checkboxes and it should work:

import pynecone as pc
class State(pc.State):
     opened: bool = False

def index():
    return pc.center(
        pc.checkbox(is_checked=State.opened, on_change=State.set_opened),
        pc.checkbox(is_checked=State.opened, on_change=State.set_opened),
    )

app = pc.App(state=State)
app.add_page(index)
app.compile()

Perhaps this could be documented better or the API could be better though

picklelo avatar Feb 04 '23 20:02 picklelo

I see. Maybe we could use a prop label= instead of passing the text as children?

Or even better would be if we could pass a variable to the checkbox, and it automatically set up on_change and is_checked (maybe the label too?) based on that variable?

Lendemor avatar Feb 04 '23 21:02 Lendemor