abadi199 / elm-input-extra

🔢 Commonly used Html element with extra functionality
http://package.elm-lang.org/packages/abadi199/elm-input-extra/latest
MIT License
51 stars 12 forks source link

Input identifier in update event #10

Closed razzeee closed 6 years ago

razzeee commented 6 years ago

I'm having a problem, as I have a List of Items and try to draw an input for each of those items.

Now I need to figure out which input was updated and match that back to my datastructure in my update function. But I only have the new value available and no reference to which item in my list it belongs.

abadi199 commented 6 years ago

Hi @Razzeee , if you can provide a code sample, I can probably help you better. If you have a unique Id for those items, you can include that Id in your Msg, so your message type will look like this:

type Msg = InputUpdated String String

...
Input.Text.input
    { maxLength = Nothing
    , onInput = InputUpdated "Input1" -- partially apply the input's Id to the Msg here
    , hasFocus = Nothing
    }
    []
    currentValue

Let me know if this solutions works for you, or perhaps I mistundersood your problem.

razzeee commented 6 years ago

Yes, sorry - I figured it out with help from the elm slack. Was confused by the update function. Where the value of the input comes as last param, not as the first, as I thought.

Btw what's the best way to do Input.defaultOptions with no onInput message?

abadi199 commented 6 years ago

You can just pass a NoOp Msg where you will just going to ignore that msg in your update function, like this:

type Msg = NoOp 

Input.Text.input (Input.Text.defaultOptions (\_ -> NoOp) ...

I hope that helps. I'm gonna close this issue now.