mdgriffith / style-elements

Create styles that don't mysteriously break!
http://package.elm-lang.org/packages/mdgriffith/style-elements/latest
BSD 3-Clause "New" or "Revised" License
445 stars 49 forks source link

Input.text doesn't reflect it's value in the UI #153

Open paulsonnentag opened 6 years ago

paulsonnentag commented 6 years ago

The big picture of what I'm trying to do

I want to be able to change the value of a text field by changing the value in the model. In my application the changes didn't get reflected in the displayed value of the input field.

What I did

I've created an minimal example where I set the value of the input field to a fixed value:

https://ellie-app.com/N7Np2wTJjBa1

What I Expected To Happen

The text in the input field shouldn't change when the user tries to enter text.

What Actually Happened

The text in the input field changes when the user enters text. This leads to a discrepancy between the defined view and the rendered ui.

I think that the problem is that the value get's set as an attribute and not a property

If I inspect the element with the devtools in chrome the correct value is set (123)

screen shot 2018-07-16 at 15 23 38

The property "value" has the wrong value

$0.value // = "123asdf"

The attribute "value" has the correct value

$0.getAttribute("value") // 123

Versions

paulsonnentag commented 6 years ago

As a temporary workaround I've added the value as a property

Input.text None
                [ property "value" (Encode.string model.text) -- set value explicitly as property
                ]
                { onChange = ChangeInput
                , value = model.text
                , label =
                    Input.placeholder
                        { label = Input.labelLeft (el None [ ] (text "Search"))
                        , text = "placeholder"
                        }
                , options = []
                }