Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f65efb5
commit 6c6e0e5
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const $ = document.querySelector.bind(document); | ||
const $$ = document.querySelectorAll.bind(document); | ||
|
||
// https://github.com/facebook/react/issues/11488#issuecomment-347775628 | ||
const setValue = (input, value) => { | ||
let lastValue = input.value; | ||
input.value = value; | ||
let event = new Event('input', { bubbles: true }); | ||
// hack React15 | ||
event.simulated = true; | ||
// hack React16 内部定义了descriptor拦截value,此处重置状态 | ||
let tracker = input._valueTracker; | ||
if (tracker) { | ||
tracker.setValue(lastValue); | ||
} | ||
input.dispatchEvent(event); | ||
} | ||
|
||
setValue($('input[name=billingAddress\\.firstName]'), 'Billy'); | ||
setValue($('input[name=billingAddress\\.lastName]'), 'Billington'); | ||
setValue($('input[name=billingAddress\\.line1]'), '123 Billing Street'); | ||
setValue($('input[name=billingAddress\\.line2]'), 'Billingville'); | ||
setValue($('input[name=billingAddress\\.city]'), 'Billing-on-Sea'); | ||
setValue($('input[name=billingAddress\\.postCode]'), 'SW19 2BB'); | ||
setValue($('input[name=billingAddress\\.phone]'), '07654111111'); |