Skip to content
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

The onSubmitFunction for a form doesn't work. #47

Closed
Albert-Gao opened this issue Aug 22, 2017 · 6 comments
Closed

The onSubmitFunction for a form doesn't work. #47

Albert-Gao opened this issue Aug 22, 2017 · 6 comments

Comments

@Albert-Gao
Copy link

fun restoreListValues(e: Event) {
    println("I'm here")
}

fun doForm(trTag: TR) {
    trTag.td {
        form {
            name = "fmform"
            encType = FormEncType.textPlain
            action = "/server/"
            method = FormMethod.post
            onSubmitFunction = {
                event - > restoreListValues(event)
            }
        }
    }
}

After executing, nothing happens to that form, I could use onSubmit, and the final form will have the onsubmit value, but the problem is that it expects a string, which means I could only refer to the final compiled javascript code which has no way to access the kotlinJS context.

What I want is simple, just use a kotlinJS method to handle the onsubmit event of a form.
How to achieve that?

@Albert-Gao Albert-Gao changed the title The onSubmitFunction for form doesn't work. The onSubmitFunction for a form doesn't work. Aug 22, 2017
@cy6erGn0m
Copy link
Contributor

cy6erGn0m commented Aug 22, 2017

Doens't explicit return value true fix the issue? onSubmitFunction = { event -> restoreListValues(event); true }

@Albert-Gao
Copy link
Author

@cy6erGn0m
Thanks for the reply
But no...

This is the result:

<form name="fmform" enctype="text/plain" action="" method="post">

@cy6erGn0m
Copy link
Contributor

Are you trying to generate javascript handler on server side?

@Albert-Gao
Copy link
Author

Nope, this is the code for the client side, I use kotlinJS

@cy6erGn0m
Copy link
Contributor

Are you sure it doesn't print "I'am here"? js dom builder simply do event handler registration so you can't see it in html. I've just tried to add the following integration test and it works well

fun assignEvent() {
        val wrapper = wrapper()
        var invoked = false

        wrapper.append {
            form {
                id = "my-form"
                onSubmitFunction = { event ->
                    invoked = true
                }
            }
        }

        val event = document.createEvent("Event")
        event.initEvent("submit", true, true)

        (wrapper.getElementsByTagName("form").asList().first { it.id == "my-form" } as HTMLFormElement).dispatchEvent(event)

        assertTrue { invoked }
    }

@Albert-Gao
Copy link
Author

It works. Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants