handling input values without using form #602
Answered
by
acivitillo
acivitillo
asked this question in
Question
-
I am trying to connect input values to state, I think this is normal in React? However, when I do this the input element in the webpage becomes uneditable. from black import click
from idom import html, run, use_state, component
import requests
@component
def create_user():
value, set_value = use_state({"username": ""})
return html.div(create_user_form(value, set_value))
@component
def create_user_form(value, set_value):
"""
endpoint: /api/users
schema: {
"username": "string",
"name": "string",
"surname": "string",
"email": "string"
}"""
def handle_click(event):
print("this", event)
username = html.label(
"username ",
html.input({"name": "username", "value": value["username"]}),
html.br(),
)
btn = html.button({"onClick": handle_click}, "Submit")
return html.div([username, btn])
run(create_user, port=8001) |
Beta Was this translation helpful? Give feedback.
Answered by
acivitillo
Jan 20, 2022
Replies: 1 comment 4 replies
-
ok I figured it out, we need to update the state as we type, this means we need to call a function to set the value state html.input(
{
"type": "text",
"placeholder": "Your message...",
"value": email, #this
"onChange": lambda event: set_email(event["target"]["value"]), #< and this
}
), |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
rmorshea
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ok I figured it out, we need to update the state as we type, this means we need to call a function to set the value state
onChange
, check the 2 lines I added below. Question, how does this look like performance wise? We are hitting the server with a lot of events now, I guess this is why we are using websockets?