futureworkz/elm-autocomplete/1.0.0

NOTE: the latest version is 1.0.2

Autocomplete

Autocomplete contains the main logic to handle auto-complete. The state and logic of Autocomplete should reside within your model. Please refer to our examples to see how it all linked up.

To render the Autocomplete, please refer to Autocomplete.View or Autocomplete.Styled.

Types

The opaque type of Autocomplete

type alias ViewState a =
{ query : String
, choices : List a
, ignoreList : List a
, selectedIndex : Maybe Int
, status : ViewStatus
}

Record to expose common values of Autocomplete to be used for display

= NotFetched
| Fetching
| Error String
| FetchedChoices

A useful union type for rendering the correct view for each state of Autocomplete

type alias Choices a =
Choices a

Record to hold the query and choices for fetching and displaying

type alias Msg a =
Msg a

Opaque type of Autocomplete internal msg

State Management

init : Choices a -> (Choices a -> Task String (Choices a)) -> Autocomplete a

Initialize the Autocomplete

update : Msg a -> Autocomplete a -> ( Autocomplete a, Cmd (Msg a) )

Update the Autocomplete state

Helpers

reset : Choices a -> Autocomplete a -> Autocomplete a

Reset the Autocomplete State

Returns the selectedValue

Accessors

viewState : Autocomplete a -> ViewState a

Returns the ViewState of the Autocomplete

query : Autocomplete a -> String

Returns the query of the Autocomplete

choices : Autocomplete a -> List a

Returns the current list of choices

selectedIndex : Autocomplete a -> Maybe Int

Returns the selected index of the Autocomplete

isSelected : Maybe Int -> Int -> Bool

Helper function to calculate if an index is selected