This module is useful if you want to add a Select Form element to your app, with the options being searchable and coming from the backend.
Init a SearchSelect.Model in your model.
myInitialModel : MyModel
myInitialModel =
{ mySearchSelect = SearchSelect.init "https://example.com/search" Decode.string
}Add a SearchSelect.Msg to your Msg.
type MyMsg
= UpdateMySearchSelect SearchSelect.MsgUse in your update function.
myUpdate : Msg -> Model -> ( Model, Cmd Msg )
myUpdate msg model =
case msg of
UpdateMySearchSelect selectMsg ->
let
( newSelect, cmd ) =
SearchSelect.update selectMsg mode.mySearchSelect
in
{ model | mySearchSelect = newSelect } ! [ cmd ]Transform an SearchSelect.Model into an SearchSelect.View, which allows us to pipe View Setters on it.
myView : Model -> Html Msg
myView model =
div
[]
[ model.mySearchSelect
|> SearchSelect.view .name
-- pipe view setters here, for example |> setIsLocked 'your logic here'
]Transforms an SearchSelect.View into Html SearchSelect.Msg
myView : Model -> Html Msg
myView model =
div
[]
[ SearchSelect.view model.mySearchSelect .name
|> SearchSelect.render
|> Html.map UpdateMySearchSelect
]ReInitialise your SearchSelect.Model.
Set the initial option of your SearchSelect.Model.
Change the option of your SearchSelect.Model.
This function allows you to disable specific options.
Set whether your search-select is in error mode (red border).
Set whether your search-select is locked (disabled).
Set whether your search-select is clearable (x icon).
Set the default label, for example (-- NOTHING SELECTED --).
Give your search-select an id. Can be useful for DOM selectors (focus, WebComponents etc.)
Whether your search-select was changed. Useful if you want to disable save buttons unless there were changes etc.
Get the initial option of your search-select.
Get the current option of your search-select. This is what you'd use to display the data somewhere outside of your search-select, or to send the data to the backend for example etc.
Useful if you need the id of the search select in your update function, to set focus etc.
Add a SearchSelect.Model to your model.