Skip to content
This repository has been archived by the owner on May 2, 2024. It is now read-only.

Update a text input problems #65

Closed
simonh1000 opened this issue Nov 28, 2016 · 7 comments
Closed

Update a text input problems #65

simonh1000 opened this issue Nov 28, 2016 · 7 comments

Comments

@simonh1000
Copy link
Contributor

simonh1000 commented Nov 28, 2016

Hi, I will try to work on an example, but wanted to flag a problem straight away. I have a text input that filters the possible choices as you type. When you click on a choice it updates the text input.

That works, but if you then start deleting the input text, such that more choices appear again, then clicking a second time on the list does not update the text input any more.

Video at: https://youtu.be/L8DbIBFF5_U?rel=0

Note how at the end the input value is "Customer 2", but you do not see that in the input box.

If you have any ideas, I would welcome it. (I'm certainly not convinced that the problem lies with elm-form, but I do something similar on a simpler form elsewhere in my site without elm-form, and then I don't have the same issues)

@pablohirafuji
Copy link
Contributor

Hi! I think your problem is related to this issue: #54

Try setting the value attribute of the input to reflect the value of the input stored in the model.

Let me know if it works :)

@simonh1000
Copy link
Contributor Author

I'm so glad I'm not alone!

Note that I an using a Text Input, not a text area.

The value is updating correctly I think. If you look at the video it ends at "Customer 2" but that is not reflected in the UI

@pablohirafuji
Copy link
Contributor

Yes, this solution is for the UI, e.g.:

Input.textInput state
             [ class "form-control"
             , value (Maybe.withDefault "" state.value)
             ]

This should solve the UI not reflecting the state. The note on Initial values and reset on the doc have more information.

@simonh1000
Copy link
Contributor Author

Thanks - that worked. Now I just have to see what 'types too fast means'!

@pablohirafuji
Copy link
Contributor

pablohirafuji commented Dec 1, 2016

Maybe it's related to how good your hardware is, but you can try this to reproduce the bug:

  1. Type something in the input (e.g: pablohirafuji| <-- caret representation)
  2. Move the caret to the start of your typed text in the input (e.g: |pablohirafuji)
  3. Bash at the keyboard with all your fingers until the caret go to the end of the input (should see something like this: ljkgsefjlkgsdfpablohirafujilkjashljkhdf|)

Please note that this bug only occurs when using the value attribute to reflect the model's value. By default, the package use defaultValue. The defaultValue attribute only work on unmodified inputs. That's why when you make any change to the input's value, it no longer reflect the model's value, but still sends the input's value to the update function using the oninput event.

@alexmunda
Copy link

It feels unexpected that only defaultValue is updated when calling Input.textInput. Anyhow, thanks @pablohirafuji for pointing out the solution and referencing the docs.

@pablohirafuji
Copy link
Contributor

@alexmunda Yeah, I also thought so. But setting the value attribute has hard side effect on Test frameworks, while defaultValue has practically no side effect. The user can always set the value, but not unset.

Just to make it clear to anyone who read this issue, the "type too fast" bug is not related to the package, it's an Elm/Virtual Dom issue. Last time I checked, React has a workaround doing something like this:

  • If the input is focused, unset the value attribute, otherwise, set the value attribute

Witch brings other issues, but all managed internally.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants