mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 07:08:01 +00:00
Add Fill An Input With A Ton Of Text as a javascript til
This commit is contained in:
@@ -10,7 +10,7 @@ smart people at [Hashrocket](http://hashrocket.com/).
|
||||
For a steady stream of TILs from a variety of rocketeers, checkout
|
||||
[til.hashrocket.com](https://til.hashrocket.com/).
|
||||
|
||||
_594 TILs and counting..._
|
||||
_595 TILs and counting..._
|
||||
|
||||
---
|
||||
|
||||
@@ -222,6 +222,7 @@ _594 TILs and counting..._
|
||||
- [Destructuring The Rest Of An Array](javascript/destructuring-the-rest-of-an-array.md)
|
||||
- [Enable ES7 Transforms With react-rails](javascript/enable-es7-transforms-with-react-rails.md)
|
||||
- [Expand Emojis With The Spread Operator](javascript/expand-emojis-with-the-spread-operator.md)
|
||||
- [Fill An Input With A Ton Of Text](javascript/fill-an-input-with-a-ton-of-text.md)
|
||||
- [Freeze An Object, Sorta](javascript/freeze-an-object-sorta.md)
|
||||
- [Globally Install A Package With Yarn](javascript/globally-install-a-package-with-yarn.md)
|
||||
- [Immutable Remove With The Spread Operator](javascript/immutable-remove-with-the-spread-operator.md)
|
||||
|
||||
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