address comment on doing this only for optionals
This commit is contained in:
parent
1cddb88030
commit
31462ad14d
@ -18,6 +18,7 @@ from reflex.event import (
|
|||||||
prevent_default,
|
prevent_default,
|
||||||
)
|
)
|
||||||
from reflex.utils.imports import ImportDict
|
from reflex.utils.imports import ImportDict
|
||||||
|
from reflex.utils.types import is_optional
|
||||||
from reflex.vars import VarData
|
from reflex.vars import VarData
|
||||||
from reflex.vars.base import LiteralVar, Var
|
from reflex.vars.base import LiteralVar, Var
|
||||||
|
|
||||||
@ -400,9 +401,11 @@ class Input(BaseHTML):
|
|||||||
value = props.get("value")
|
value = props.get("value")
|
||||||
|
|
||||||
# React expects an empty string(instead of null) for uncontrolled inputs.
|
# React expects an empty string(instead of null) for uncontrolled inputs.
|
||||||
if value is not None:
|
if value is not None and is_optional(
|
||||||
|
(value_var := Var.create(value))._var_type
|
||||||
|
):
|
||||||
props["value"] = ternary_operation(
|
props["value"] = ternary_operation(
|
||||||
((value_var := Var.create(value)) != Var.create(None))
|
(value_var != Var.create(None))
|
||||||
& (value_var != Var(_js_expr="undefined")),
|
& (value_var != Var(_js_expr="undefined")),
|
||||||
value,
|
value,
|
||||||
"",
|
"",
|
||||||
|
@ -9,6 +9,7 @@ from reflex.components.core.breakpoints import Responsive
|
|||||||
from reflex.components.core.debounce import DebounceInput
|
from reflex.components.core.debounce import DebounceInput
|
||||||
from reflex.components.el import elements
|
from reflex.components.el import elements
|
||||||
from reflex.event import EventHandler, input_event, key_event
|
from reflex.event import EventHandler, input_event, key_event
|
||||||
|
from reflex.utils.types import is_optional
|
||||||
from reflex.vars.base import Var
|
from reflex.vars.base import Var
|
||||||
from reflex.vars.number import ternary_operation
|
from reflex.vars.number import ternary_operation
|
||||||
|
|
||||||
@ -100,10 +101,11 @@ class TextFieldRoot(elements.Div, RadixThemesComponent):
|
|||||||
value = props.get("value")
|
value = props.get("value")
|
||||||
|
|
||||||
# React expects an empty string(instead of null) for uncontrolled inputs.
|
# React expects an empty string(instead of null) for uncontrolled inputs.
|
||||||
if value is not None:
|
if value is not None and is_optional(
|
||||||
# props["value"] = Var(_js_expr=f"{value} ?? ''", _var_type=str)
|
(value_var := Var.create(value))._var_type
|
||||||
|
):
|
||||||
props["value"] = ternary_operation(
|
props["value"] = ternary_operation(
|
||||||
((value_var := Var.create(value)) != Var.create(None))
|
(value_var != Var.create(None))
|
||||||
& (value_var != Var(_js_expr="undefined")),
|
& (value_var != Var(_js_expr="undefined")),
|
||||||
value,
|
value,
|
||||||
"",
|
"",
|
||||||
|
Loading…
Reference in New Issue
Block a user