bluedogtraining / bdt-elm / Form.TextArea

This module is useful if you want to add an TextArea Form element to your app.

Initialise and update


type Model

Add a TextArea.Model to your model.

type alias MyModel =
    { myTextArea : TextArea.Model
    }

init : Model

Add a TextArea.Model to your model.

myInitialModel : MyModel
myInitialModel =
    { myTextArea = TextArea.init -- optionally pipe into State Setters
    }


type alias Msg =
Internal.Msg

Add a TextArea.Msg to your Msg.

type MyMsg
    = UpdateMyTextArea TextArea.Msg

update : Msg -> Model -> Model

Use in your update function.

myUpdate : Msg -> Model -> ( Model, Cmd Msg )
myUpdate msg model =
    case msg of
        UpdateMyTextArea inputMsg ->
            { model | myTextArea = TextArea.update inputMsg mode.myTextArea } ! []

View and render

view : Model -> View

Transform an TextArea.Model into an TextArea.View, which allows us to pipe View Setters on it.

myView : Model -> Html Msg
myView model =
    div
        []
        [ TextArea.view model.myTextArea -- pipe view setters here, for example |> setIsLocked 'your logic here'
        ]

render : View -> Html.Styled.Html Msg

Transforms an TextArea.View into Html TextArea.Msg

myView : Model -> Html Msg
myView model =
    div
        []
        [ TextArea.view model.myTextArea
            |> TextArea.render
            |> Html.map UpdateMyTextArea
        ]

State Setters

reInitialise : Model -> Model

ReInitialise your TextArea.Model.

reset : Model -> Model

Reset your TextArea.Model.

setInitialValue : String -> Model -> Model

Set the initial value of your TextArea.Model.

setValue : String -> Model -> Model

Change the value of your TextArea.Model.

setReplacements : List ( String, String ) -> Model -> Model

Set a ist of string that should be replaced.

View Setters

setPlaceholder : String -> View -> View

Set a placeholder for your input.

setMaxLength : Basics.Int -> View -> View

Set the max length for your input string.

setIsError : Basics.Bool -> View -> View

Set whether your input is in error mode (red border).

setIsLocked : Basics.Bool -> View -> View

Set whether your input is locked (disabled).

setId : String -> View -> View

Give your input an id. Can be useful for DOM selectors (focus, WebComponents etc.)

setShouldWrap : Basics.Bool -> View -> View

Set whether you want text to wrap or not

Getters

getInitialValue : Model -> String

Get the initial value of your input.

getValue : Model -> String

Get the current value of your input. This is what you'd use to display the data somewhere outside of your input, or to send the data to the backend for example etc.

getIsChanged : Model -> Basics.Bool

Whether your input was changed. Useful if you want to disable save buttons unless there were changes etc.

getId : View -> Maybe String

Useful if you need the id of the input in your update function, so set focus etc.