nathanbraun / elm-multiselect / Multiselect

An implementation of multiselect control built with and for Elm.

Please, check example/src/MinimalExample.elm for the minimal example on how to use this library.

Helpers

initModel : List ( String, String ) -> String -> InputInMenu -> Model

Init model based on the values : List (String, String) and id : String provided by the user.

model =
    { multiselect = Multiselect.initModel [ ( "one", "The 1st option" ), ( "two", "The 2nd option" ), ( "three", "The 3rd option" ) ] "id_1"
    }

getSelectedValues : Model -> List ( String, String )

Get selected values : List (String, String)

populateValues : Model -> List ( String, String ) -> List ( String, String ) -> Model

Populate model with values : List (String, String) and preselect selected : List (String, String).

clearInputText : Model -> ( Model, Platform.Cmd.Cmd Msg )

Clear the input text: (Model, Cmd Msg)

getValues : Model -> List ( String, String )

Get the full list of values : List (String, String)


type InputInMenu
    = Show
    | Hide

Whether or to show the input field as the first result of the menu or not useful for tagging

Model


type Model

Opaque type that holds the model

type alias Model =
    { multiselect : Multiselect.Model
    }

Msg


type Msg

Opaque type for internal library messages

OutMsg


type OutMsg
    = Selected (( String, String ))
    | Unselected (( String, String ))
    | Cleared
    | NotFound String

Transparent type for external library messages

View

view : Model -> Html Msg

Render the view

Html.map MultiselectMsg <| Multiselect.view model.multiselect

Update

update : Msg -> Model -> ( Model, Platform.Cmd.Cmd Msg, Maybe OutMsg )

Update the control state

MultiselectMsg subMsg ->
    let
        ( subModel, subCmd ) =
            Multiselect.update subMsg model.multiselect
    in
        { model | multiselect = subModel } ! [ Cmd.map MultiselectMsg subCmd ]

Subscriptions

subscriptions : Model -> Platform.Sub.Sub Msg

Subscribe for messages

Sub.map MultiselectMsg <| Multiselect.subscriptions model.multiselect