Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elm - input type checkbox

I'm trying to set a type attribute for input:

input [ type "checkbox" ] []

But I get an error:

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 could I finally set this attribute?

like image 909
Akhmedzianov Danilian Avatar asked Feb 26 '18 21:02

Akhmedzianov Danilian


2 Answers

The correct function is indeed named type_ and is located in the Html.Attributes module. Ensure that you are importing 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 (..)
like image 51
Chad Gilbert Avatar answered Oct 17 '22 16:10

Chad Gilbert


Looks like you are missing an import statement in your elm file, you can import just that attribute via

import Html.Attributes exposing (type_)

or, just import everything, like so

import Html.Attributes exposing (..)

then the example you posted would work.

input [ type_ "checkbox" ] []

What I Like to do when I am writing html in elm, and need to look something up, is use this site and in the top right I can just search for the thing I am looking for. Comes complete with examples even! :)

Happy Elming!

like image 6
JosephStevens Avatar answered Oct 17 '22 17:10

JosephStevens