3

My first steps with pynecone: I'm trying to pre-fill a textarea based on checkboxes and dropdowns, and then enable the user to edit the generated text.

However, when I hook up the events such that I can populate the textarea, whenever the user enters a character, the on_change event fires and moves the cursor to the end of the text area, making editing impossible.

Is there a way to do this?

Here is my minimal code example:

from pcconfig import config

import pynecone as pc

class State(pc.State):
    q1_response: str

    q1_c0: bool = False
    q1_c1: bool = False
    q1_c2: bool = False
    
    def add_response(self, *args):
    
        text = ''
        if self.q1_c0:
            text += q.options[0][1] + '\n'
        if self.q1_c1:
            text += q.options[1][1] + '\n'
        if self.q1_c2:
            text += q.options[2][1] + '\n'

        self.q1_response = text.strip()


class Question:
    def __init__(self):
        self.q = 'This is the question'
        self.options = [
            ('None', 'Nothing'),
            ('Answer 1', 'The long answer 1.'),
            ('Answer 2', 'The long answer 2.'),
        ]

q = Question()


def index():
    return pc.container(
        pc.text(q.q, font_size="1.5em"),
        pc.vstack(

            pc.checkbox(q.options[0][0] + ' - ' + q.options[0][1], on_change=State.set_q1_c0),
            pc.checkbox(q.options[1][0] + ' - ' + q.options[1][1], on_change=State.set_q1_c1),
            pc.checkbox(q.options[2][0] + ' - ' + q.options[2][1], on_change=State.set_q1_c2),

            pc.button("Add", on_click=State.add_response, bg="blue", color="white"),

            pc.text_area(
                value = State.q1_response,
                placeholder = 'The long answer will go here',
                on_change = State.set_q1_response,
                rows = 8,
            ),
        ),
    )   


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

I tried a variety of events, but the only way I can get pynecone to update the textbox (see the example), editing of the textarea by the user is impacted.

I did find a recent issue that seems to be related to my observations ... so it could be an open bug github.com/pynecone-io/pynecone/issues/900

0

1 Answer 1

3

In the current version of the pynecone, it is a bug.
https://github.com/pynecone-io/pynecone/issues/1087
So there is no solution for it right now.
But we can continue to observe and wait its updates.

Not the answer you're looking for? Browse other questions tagged or ask your own question.