denim-ui icon indicating copy to clipboard operation
denim-ui copied to clipboard

TextInput needs text to be Observable[string]. Doesn't work for Subject[string]

Open kristianhasselknippe opened this issue 4 years ago • 0 comments

component MyInput(state: Subject[string]):
  stack(width = 200.0):
    text(text = "", alignment = Alignment.Center, color = black)
    textInput(
      alignment = Alignment.Left,
      text <- state,
      color = black,
      minWidth = 100.0,
      placeholder = "...insert text",
      onChange = 
        proc(x: string): void {.closure.} = 
          state <- x
          echo("newVal: ", x)
      ,
    )

fails but

component MyInput(state: Subject[string]):
  stack(width = 200.0):
    text(text = "", alignment = Alignment.Center, color = black)
    textInput(
      alignment = Alignment.Left,
      text <- state.source,
      color = black,
      minWidth = 100.0,
      placeholder = "...insert text",
      onChange = 
        proc(x: string): void {.closure.} = 
          state <- x
          echo("newVal: ", x)
      ,
    )

works

kristianhasselknippe avatar Jun 07 '21 13:06 kristianhasselknippe