Docs: add hx-vals example using the event object (#825)

This commit is contained in:
Alejandro Schmeichler 2022-02-17 09:15:48 -04:00 committed by GitHub
parent f302ad6fdd
commit c49ce64d2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,6 +18,14 @@ If you wish for `hx-vals` to *evaluate* the values given, you can prefix the val
<div hx-get="/example" hx-vals='js:{myVal: calculateValue()}'>Get Some HTML, Including a Dynamic Value from Javascript in the Request</div>
```
When using evaluated code you can access the `event` object. This example includes the value of the last typed key within the input.
```html
<div hx-get="/example" hx-trigger="keyup" hx-vals='js:{lastKey: event.key}'>
<input type="text" />
</div>
```
### Security Considerations
* By default, the value of `hx-vals` must be valid [JSON](https://developer.mozilla.org/en-US/docs/Glossary/JSON).