MadonnaMat / elm-select-two / SelectTwo

This library is the basic controls for your model's select2 object and some helper methods

Basic Controls

update : (Types.SelectTwoMsg msg -> msg) -> Types.SelectTwoMsg msg -> Maybe (String -> Types.AjaxParams -> Basics.Bool -> ( Types.Model b msg, Platform.Cmd.Cmd msg )) -> Types.Model b msg -> ( Types.Model b msg, Platform.Cmd.Cmd msg )

used in your elm project's update as a way to control the select two boxes on screen it is used by

yourUpdate : Msg -> Model -> ( Model, Cmd Msg )
yourUpdate msg model =
    let
        ajaxSend =
            Just
                (\id_ params reset ->
                    case id_ of
                        "test-4" ->
                            ( model
                            , SelectTwo.send <| TestAjax params reset
                            )

                        _ ->
                            ( model
                            , Cmd.none
                            )
                )
    in
    SelectTwo.update SelectTwo stmsg ajaxSend model

new : Types.SelectTwoDropdown msg -> Types.Model b msg -> Types.Model b msg

Create a new instance of the selectTwo record in your model

map : (Types.SelectTwo msg -> Types.SelectTwo msg) -> Types.Model b msg -> Types.Model b msg

modify selectTwo record in your model

setSearch : String -> Types.Model b msg -> Types.Model b msg

set the search parameter in your selectTwo record

Ajax Methods

setLoading : Types.AjaxParams -> Basics.Bool -> Types.Model b msg -> Types.Model b msg

To be used in your ajax functions to set loading state before sending

    TestAjax params reset ->
        let
            url =
                "//api.github.com/search/repositories"

            buildUrl =
                let
                    term =
                        if params.term == "" then
                            "test"
                        else
                            params.term
                in
                    (url ++ "?q=" ++ term ++ "&page=" ++ (toString params.page))
        in
            SelectTwo.setLoading params reset model ! [ sendAjax buildUrl (TestRes params) ]

setList : List (Types.GroupSelectTwoOption msg) -> Types.AjaxParams -> Types.Model b msg -> Types.Model b msg

Set the list from the return of your ajax command

    TestRes params (Ok str) ->
        let
            ( list, newParams ) =
                processResult Test str params
        in
            SelectTwo.setList list newParams model ! []

Helper Methods

basicSelectOptions : (a -> msg) -> List ( a, String ) -> List (Types.GroupSelectTwoOption msg)

turn a list of Tuples into a list of GroupSelectTwoOptions with one group. The first parameter is their shared trigger message, the second parameter is the list of tuples which are formatted as (Key, "Display"), and the return can be used in the list option of the config

[ ( Just "a", "a" )
, ( Just "b", "b" )
, ( Just "c", "c" )
]
    |> SelectTwo.basicSelectOptions Test

basicGroupSelectOptions : (a -> msg) -> List ( a, String, String ) -> List (Types.GroupSelectTwoOption msg)

turn a list of Tuples3 into a list of GroupSelectTwoOptions with actual grouping. The first parameter is their shared trigger message, the second parameter is the list of tuples which are formatted as (Key, "Display", "Group Name"), and the return can be used in the list option of the config

[ ( Just "a", "a", "Group 1" )
, ( Just "b", "b", "Group 1" )
, ( Just "c", "c", "Group 2" )
]
    |> SelectTwo.basicSelectOptions Test

defaultsFromList : List msg -> List (Types.GroupSelectTwoOption msg) -> List (Types.SelectTwoOption msg)

Quick helper way of getting defaults list from a GroupSelectTwoOption list

send : msg -> Platform.Cmd.Cmd msg

Quick helper method for sending a message and running through your update function agian

update msg model =
    case msg of
        Test1 ->
            ( model
            , SelectTwo.send Test2
            )

        Test2 ->
            ( model
            , Cmd.none
            )