Elm Radio button

I have created a toggle switch in ELM but I want to use JSON.decode such that if the toggle button is ON, the Json indicates it such that { toggle: ON} and similarly if its OFF. Also, I have mentioned the default toggle as ON (onClick) but it doesn’t seem to be ON. How can I achieve this?

The codepen version of it is here ( which includes the styles ): https://ellie-app.com/bKG3H5mxKj3a1

1 Like

It is good practice if the view is always derived from the model (instead of using the inherited stated from the DOM), meaning that the checked status should be controlled by Elm.

input [ type_ "checkbox", checked model.buttonStatus ]

Then your message can be:

msg =
  if model.buttonStatus then
    OFF
 else
   ON
2 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.