question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

HTML input value is not reflected on the view

See original GitHub issue

It seems the value attribute of an input field is not correctly reflected on the view when the model changes.

case class Model(input: String)

input(`type` := "text", attribute("value", model.input))

The input field is updated either on Msg.SymbolChanged or reset (input = "") on Msg.Subscribe.

// view
input(`type` := "text", attribute("value", model.input), onInput(s => Msg.SymbolChanged(s)))

// update
case Msg.SymbolChanged(in) =>
  model.copy(input = in) -> Cmd.Empty

case Msg.Subscribe =>
  val nm  = model.copy(input = "")
  val cmd = model.ws.map(ws => Cmd.Batch(ws.publish(WsIn.Subscribe.asJson.noSpaces), refocusInput))
  nm -> cmd.getOrElse(Cmd.Empty)

Everytime the model is updated in the first message, I can see the HTML input value is updated (seeing this by inspecting the element in the browser). However, when the Subscribe message is handled and the input in the model is reset, the value attribute is properly reset as well, but the view remains with the previous value.

Here’s an example from the trading application, right after clicking subscribe, where I first noticed the issue.

issue

The value attribute is reset but the view still shows the previously entered value “CHFEUR”. I’d expect the input field to be cleared up as well.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
aumanncommented, Feb 27, 2022

For future reference, if there should be more issues, an entry level explanation of attributes vs DOM properties: https://stackoverflow.com/a/6004028/14188171

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTML Input is not updating value attribute on change
For some reason the input tags in my form are not updating the value attribute when they are changed view the actual element...
Read more >
Input not updating on page while having its value set, can be ...
But when I check the source, its value attribute is set and it has the string I have set, but it doesn't get...
Read more >
<input>: The Input (Form Input) element - HTML
The <input> HTML element is used to create interactive controls for web-based forms in order to accept data from the user; a wide...
Read more >
Selected input value not reflecting in JS controller of LWC
The selected input values are not reaching JS controller. Tried multiple ways but the value is showing as null. Below is the code....
Read more >
HTML Input Types - W3Schools
A hidden field often stores what database record that needs to be updated when the form is submitted. Note: While the value is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found