Permalink
Browse files

Create parade-billing-address.ts

  • Loading branch information...
richardscarrott committed Dec 9, 2018
1 parent f65efb5 commit 6c6e0e5e07305ac9beb3d8ccd8ee9d68b57aed05
Showing with 25 additions and 0 deletions.
  1. +25 −0 snippets/parade-billing-address.ts
@@ -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');

0 comments on commit 6c6e0e5

Please sign in to comment.