Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Work with elm and select

Tags:

elm

I try to understand how elm works with a custom example.

durationOption duration =
  option [value (toString duration) ] [ text (toString duration)]

view : Model -> Html Msg
view model =
  Html.div []
    [ h2 [] [ text "Month selector"]
    , select []
      (List.map durationOption [1..12])    
    ]

It's an easy example to work with a select. I would like, each time I change the month value it multiplies to value by 10 for example. According to the documentation there is not events like onChange or onSelect, do I have to create mine with on ?

like image 897
billyJoe Avatar asked May 22 '16 16:05

billyJoe


People also ask

What is your Elm?

One company with one focus: Servicing the financial aid industry by empowering schools to work with a broad array of lenders using a single processing system and helping students find the best loan for their needs. Learn more about Your ELM Product Suite

Why choose elmselect for student loans?

ELM makes it easy to consolidate all of your private student loan processing activities in one place. Partner with ELM Resources and connect with the largest network of schools. See why ELMSelect is the best choice to select the perfect loan for you.

How to run elm from process steps?

after filling all mandatory and required fields you have to press button in upper left corner “Start“. This will start ELM and dpending your process steps functions will trigger. Below screen shot is of after completion of Process steps. after Successfull execution of ELM you can see the list recird by clicking on button “Show List Records“.

How to use Elm in PFTC?

You need to goto PFTC and open WS14000029 then goto Workflow builder then goto its Basic Data and in Agent assignment Task you need to check Genral Task. Above is the Basic Configuration for ELM and is ready to use. 1) For using ELM we need to create Mapping Formats.


1 Answers

For future reference for Elm-newbies (like me): with Elm 0.18.0 + elm-lang/html 2.0.0, the onInput event (see code below) works. (Also notice the difference in int range notation (List.range 0 12 instead of [0..12]).

import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (onInput)


main =
  Html.beginnerProgram
    { model = model
    , view = view
    , update = update
    }



-- MODEL


type alias Model =
  { duration : Int
  }


model : Model
model =
  Model 0



-- UPDATE


type Msg
    = SetDuration String


update : Msg -> Model -> Model
update msg model =
  case msg of
    SetDuration s ->
      let result =
        String.toInt s
      in
        case result of
          Ok v ->
            { model | duration = v }

          Err message ->
            model


-- VIEW


view : Model -> Html Msg
view model =
  div []
    [ select [ onInput SetDuration ]
             (List.range 0 12 |> List.map intToOption)
    , div [] [ text <| "Selected: " ++ (toString model.duration) ]         
    ]


intToOption : Int -> Html Msg
intToOption v =
  option [ value (toString v) ] [ text (toString v) ]
like image 176
Ferenc Dósa-Rácz Avatar answered Oct 05 '22 20:10

Ferenc Dósa-Rácz