New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onSubmit event cannot be decoded #946

Open
muelli opened this Issue Mar 5, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@muelli

muelli commented Mar 5, 2018

Ellie:
https://ellie-app.com/pYJ2XkZZZa1/0

module Main exposing (main)

import Html exposing (Html, text, div, form, input)
import Html.Attributes exposing (action, attribute, class, class, disabled, for, id, method, name, type_, value)
import Html.Events exposing (..)

import Json.Encode
import Json.Decode
import Json.Decode.Pipeline


type Msg
    = SubmitForm Json.Encode.Value

type alias Model =
 String


decodeForm =
    Json.Decode.map
        SubmitForm
        (Json.Decode.at [ "currentTarget"
--                        , "dc_field_02"
--                        , "value"
                        ]
            Json.Decode.value)


preventDefault =
    { preventDefault = True
    , stopPropagation = False
    }

onLoginSubmit : Html.Attribute Msg
onLoginSubmit =
    onWithOptions
        (Debug.log "onLoginSubmit" "submit")
        preventDefault
        decodeForm




view : Model -> Html Msg
view model =
    viewForms model



viewForms model =
    div []
        [form [
                action "javascript:void(0);"
              , onLoginSubmit
              ]

              [
                input [name "foo"] []
              , input [type_ "submit"] [text "submit!"]
              ]

        ]

update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
    case msg of
        SubmitForm formContent ->
            let
                d =
                    Debug.log "Form Content:" formContent
                    
            in
                ( model, Cmd.none )
       

init s = ("foo", Cmd.none)


main : Program Never Model Msg
main =
    Html.program
        { init = init "some token"
        , view = view
        , update = update
        , subscriptions = (\m -> Sub.none)
        }

error:

A JavaScript Error was thrown by your program:
too much recursion

I expected to be able to get my hands on the form after having submitted it. Currently it requires a weird dance around certain JSON properties.

@process-bot

This comment has been minimized.

Show comment
Hide comment
@process-bot

process-bot Mar 5, 2018

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

process-bot commented Mar 5, 2018

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment