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:
31
javascript/fill-an-input-with-a-ton-of-text.md
Normal file
31
javascript/fill-an-input-with-a-ton-of-text.md
Normal 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
|
||||
Reference in New Issue
Block a user