Skip to content
This repository was archived by the owner on Oct 9, 2022. It is now read-only.

Commit d816c62

Browse files
authored
Update dom.rst
1 parent b17fa58 commit d816c62

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

dom.rst

+6-10
Original file line numberDiff line numberDiff line change
@@ -82,22 +82,18 @@ Kweb can also read from the DOM, in this case the value of an <input> element:
8282
Kweb(port = 2395) {
8383
doc.body {
8484
val input: InputElement = input()
85-
input.on.submit {
86-
GlobalScope.launch {
87-
val value = input.getValue().await()
88-
println("Value: $value")
89-
}
85+
input.on(retrieveJs = input.valueJsExpression).submit { event ->
86+
println("Value: ${event.retrieved}")
9087
}
9188
}
9289
}
9390
}
9491
95-
Note that input.getValue() returns a `CompletableFuture<String> <https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletableFuture.html>`_.
96-
This is because it can take up to several hundred milliseconds to retrieve from the browser, and we don't want the application
97-
to block if it can be avoided. Here we use Kotlin's very powerful `coroutines <https://kotlinlang.org/docs/reference/coroutines-overview.html>`_
98-
features to avoid any unnecessary blocking.
92+
Events can evaluate a JavaScript expression and send the result to the server, in this case we give it an
93+
expression that will retrieve the value of an InputElement, conveniently provided by valueJsExpression.
9994

100-
.. note:: We discuss an even better way to read <input> values in the `Observer Pattern & State <https://docs.kweb.io/en/latest/state.html#binding-a-kvar-to-an-input-element-s-value>`_ section.
95+
.. note:: See the `Observer Pattern & State <https://docs.kweb.io/en/latest/state.html#binding-a-kvar-to-an-input-element-s-value>`_ section for
96+
another way to read input element values.
10197

10298
Supported HTML tags
10399
-------------------

0 commit comments

Comments
 (0)