クレジットカード情報用のカスタムフォームを作成するためにbraintreeの準備を整えようとしているので、単純に機能しないフォームがあります。Uncaught TypeError:FormNapperにHTMLFormElement要素または1のID文字列が必要です
私はUiBinderサンプルメッセージでこのフォームを作成していた場合ただし、:
<g:HTML ui:field="creditCardFormContainer">
<form id="credit-card-form" name="credit-card-form" action="/app/create-credit-card" method="post" target="hidden-iframe">
<label for="card-number">Card Number</label>
<div id="card-number"/>
<label for="cvv">CVV</label>
<div id="cvv"/>
<label for="expiration-date">Expiration Date</label>
<div id="expiration-date"/>
<input id="nonce" name="nonce" type="hidden" value="" />
<input type="submit" value="Add credit card" />
</form>
</g:HTML>
とタイプcredit-card-form
のチェックを行い、私は実際にそれは私が期待していタイプではないことを見ていますそれはである:
private native void setupCreditCardForm(String domId, String serverToken) /**/-{
var form = $doc.getElementById(domId);
if (form instanceof HTMLFormElement != true) {
console.log(typeof(form)); // Prints 'object'
throw new TypeError("Form must be of type HTMLFormElement"); // Gets thrown ..
}
// Never reached ..
var bt = braintree;
braintree.setup(
serverToken,
"custom",
{
id: domId,
hostedFields: {
number: {
selector: "#card-number"
},
cvv: {
selector: "#cvv"
},
expirationDate: {
selector: "#expiration-date"
}
},
onPaymentMethodReceived: function(details) {
[email protected]InfoView::onPaymentMethodReceived(Ljava/lang/String;)(details.nonce);
}
});
}-/**/;
これはなぜですか?私は明確にform
を作成しています - なぜこれはうまくいかないのですか?
hereと同様に、documentationに記載されています。 $wnd.braintree
でなければなりません
FormNapper requires an HTMLFormElement element or the id string of one.
フム、= braintree'は、 'B'は有効なオブジェクトになります。 '$ wnd.brainree'を使うと、オブジェクトはありません。私は 'ScriptInjector'を使ってbraintree JavaScriptファイルをロードしていますが、これまでsetup関数が呼び出されています。なぜ '$ wnd'が動作しないのか分かりません – displayname
' TOP_WINDOW'に 'ScriptInjector'を注入する必要があります。あるいは、フォームの代わりに 'form'要素を渡すこともできます。(Braintreeがクロスウィンドウ要素をどれくらいうまく扱っているかによる)ID: –
Omgありがとうございました! 'TOP_WINDOW'に注入した後、それは機能しました!私は今まで自分自身でこれを実現していたかどうかわかりません。 – displayname