Tab "Elm - input type"

I am trying to set an attribute typefor input:

input [ type "checkbox" ] []

But I get an error message:

It looks like the keyword `type` is being used as a variable.
input [ type "checkbox" ] []
       ^
Rename it to something else.

When i try to use

input [ type' "checkbox" ] []

I get this error:

Ran into a single quote in a variable name. This was removed in 0.18!
input [ type' "checkbox" ] []
       ^
Change it to a number or an underscore, like type_ or type1
Or better yet, choose a more descriptive name!

And if I try

input [ type_ "checkbox" ] []

I get another error:

Cannot find variable `type_`
input [ type_ "checkbox" ] []
        ^^^^^

So how can I finally set this attribute?

+4
source share
2 answers

The correct function is indeed called type_and located in the module Html.Attributes. Make sure you import it correctly.

-- this exposed type_, checked, and value (as examples)
import Html.Attributes exposing (type_, checked, value)

-- alternatively, to expose everything,
import Html.Attributes exposing (..)
+9
source

It looks like you are missing the import statement in your elm file, you can import this attribute through

import Html.Attributes exposing (type_)

or just import everything, for example

import Html.Attributes exposing (..)

then the example you posted will work.

input [ type_ "checkbox" ] []

, html , - , , . !:)

!

+6

Source: https://habr.com/ru/post/1694152/


All Articles