1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-11 02:58:01 +00:00

Add Fill An Input With A Ton Of Text as a javascript til

This commit is contained in:
jbranchaud
2018-01-09 11:31:42 -06:00
parent 499527fa90
commit 3ea95b75ed
2 changed files with 33 additions and 1 deletions

View File

@@ -0,0 +1,31 @@
# Fill An Input With A Ton Of Text
I needed to test out a form validation for an input that should render an
error when the length of the context exceeds 10,000 characters. Two small
tricks make this easy.
First, you can target any DOM element via the Chrome dev tools by selecting
it and then referencing it via the `$0` magic variable. [More details
here](https://developers.google.com/web/updates/2015/05/the-currently-selected-dom-node).
```javascript
> $0
<input>...</input>
```
Second, you can quickly and precisely generate a very long string with the
`repeat` function.
```javascript
> "a".repeat(10000)
"aaaaaaaaaaaaaaaaaaaaaaa..."
```
Combine these two tricks in the browser to fill the input with a ton of
text:
```javascript
> $0.value = "a".repeat(10000)
```
h/t Dillon Hafer