This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.
A reusable date picker component
version 3.0.1
license BSD3
native-modules False
elm-version 0.18.0 <= v < 0.19.0
Tag 3.0.1
Committed At 2018-07-17 10:07:54 UTC
elm-lang/html 2.0.0 <= v < 3.0.0 2.0.0
elm-lang/core 5.0.0 <= v < 6.0.0 5.1.1




elm package install elm-community/elm-datepicker

A reusable date picker component in Elm.


The DatePicker.init function initialises the DatePicker. It returns the initialised DatePicker and associated Cmds so it must be done in your program's init or update functions:

Note Make sure you don't throw away the initial Cmd!

init : (Model, Cmd Msg)
        ( datePicker, datePickerCmd ) =
            { model | datePicker = datePicker },
   SetDatePicker datePickerCmd

The DatePicker can be displayed in a view using the DatePicker.view function. It returns its own message type so you should wrap it in one of your own messages using

type Msg
    = ...
    | SetDatePicker DatePicker.Msg
    | ...

view : Model -> Html Msg
view model =
    div [] [
         |> SetDatePicker

To handle Msg in your update function, you should unwrap the DatePicker.Msg and pass it down to the DatePicker.update function. The DatePicker.update function returns:

  • the new model
  • any command
  • the new date as a DateEvent (Maybe Date), where DateEvent is really just Maybe with different semantics, to avoid a potentially confusing Maybe Maybe.

To create the settings to pass to update, DatePicker.defaultSettings` is provided to make it easier to use. You only have to override the settings that you are interested in.

Note The datepicker does not retain an internal idea of a picked date in its model. That is, it depends completely on you for an idea of what date is chosen, so that third tuple member is important! Evan Czaplicki has a compelling argument for why components should not necessarily have an their own state for the primary data they manage here.

someSettings : DatePicker.Settings
someSettings = 
    { defaultSettings
        | inputClassList = [ ( "form-control", True ) ]
        , inputId = Just "datepicker"

update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
    case msg of

         SetDatePicker msg ->
                ( newDatePicker, datePickerCmd, dateEvent ) =
                    DatePicker.update someSettings msg model.startDatePicker

                date =
                    case dateEvent of
                        NoChange ->

                        Changed newDate ->
                            newDate |> processDate
                { model
                    | date = date
                    , datePicker = newDatePicker
                    ! [ SetDatePicker datePickerCmd ]


See the examples folder or try it on ellie-app: simple example and bootstrap example.


The CSS for the date picker is distributed separately. You can grab the compiled CSS from here or you can grab the SCSS source from here.

Running the acceptance tests


Install the testing tools

run npm install

build the examples

cd examples && make && cd ..

Run the tests


Please file an issue if you have any difficulty running the tests.