abadi199/intl-phone-input/1.0.0

NOTE: this package is not compatible with Elm 0.19.1

IntlPhoneInput.Config

Contains types and helper functions for working with configuration of IntlPhoneInput

Config

type alias Config msg =
{ hash : String
, onChange : State -> PhoneNumber -> Cmd msg -> msg
, namespace : String
, countries : Dict String CountryData
, countriesSorter :
List ( String, CountryData ) -> List ( String, CountryData )
, dialCodeFormatter : String -> String
}

This record type holds all configuration of IntlPhoneInput.

defaultConfig : (State -> PhoneNumber -> Cmd msg -> msg) -> Config msg

Create the Config for your intlPhoneInput view function using the default configuration. You just need to specify your Msg to the function.

If you need to customize the Config, just use the record update to override the fields you want to change, e.g.:

type Msg
    = PhoneUpdated State PhoneNumber (Cmd Msg)


let
    baseConfig =
        defaultConfig PhoneUpdated
in
{ baseConfig | dialCodeFormatter = \dialCode -> "(+" ++ dialCode ++ ")" }
configWithId : String -> (State -> PhoneNumber -> Cmd msg -> msg) -> Config msg

Create the Config using a unique id value. This is an alternative to configWithSeed if you already have a unique id for your IntlPhoneInput. This is usually useful when generating dynamic forms from database, where you can use the Id from the database table as the 'unique' Id.

type Msg
    = PhoneUpdated State PhoneNumber (Cmd Msg)


config =
    baseConfig =
        configWithId "219" PhoneUpdated
configWithSeed : Int -> (State -> PhoneNumber -> Cmd msg -> msg) -> Config msg

Create the Config with a custom seed value. The seed is used to generate the hash value to generate 'unique' Id for some elements inside the IntlPhoneInput.

type Msg
    = PhoneUpdated State PhoneNumber (Cmd Msg)


config =
    baseConfig =
        configWithSeed 3876193 PhoneUpdated

Helper Functions

getPhoneNumberInputId : Config msg -> String

Helper function to get the DOM id of the phone number <input /> element.