Comments (8)
For example, I can't submit the customer details for SCA until I have first validated those inputs, but I can't do that before they click the CreditCardSubmitButton.
from react-square-payment-form.
You can create your own submit button and leverage ContextConsumer
(another undocumented component) similar to how CreditCardSubmitButton
works:
class MySubmitButton extends React.Component {
handleSubmit = createNonce => evt => {
evt.preventDefault();
console.log("validate inputs");
createNonce(evt);
};
render() {
return (
<ContextConsumer>
{context => (
<button
className="sq-creditcard"
onClick={this.handleSubmit(context.onCreateNonce)}
>
Pay
</button>
)}
</ContextConsumer>
);
}
}
Here's an example form using that custom component: https://codesandbox.io/s/react-square-payment-form-starter-41-4cbpn
You'll also notice that styles.css
in that sandbox customizes the label style using .sq-label
class.
Hope this helps!
from react-square-payment-form.
Oh thanks! I'll definitely try this out.
from react-square-payment-form.
Unless I'm misunderstanding, there's no way to do this with an uncontrolled form, right @maxbeatty? I'd prefer not to do controlled inputs and a button click handler, and instead grab form data and use a <form>
onSubmit
. Regardless, your solution still helps me a lot. Thanks!
from react-square-payment-form.
As long as your component that consumes the context is nested in SquarePaymentForm
, you should be able to attach to any event handler. Pseudo-code:
<SquarePaymentForm>
<MyForm onSubmit={/* call context.onCreateNonce */} >
<MyCustomerInfo />
<CreditCardNumberInput />
<button type="submit">Pay</button>
</MyForm>
</SquarePaymentForm>
from react-square-payment-form.
Thanks for all your help @maxbeatty ! I got this to work, but I'll have to figure out something more creative for the times that the dollar amount is $0. If I put the conditional around the element, the context gets lost and can't find the form. Is there a way to make the inputs smart enough that when the dollar amount is zero, they don't show up?
from react-square-payment-form.
Hmm I'm not sure of the best way to handle $0 charges but maybe someone in the community Slack can help https://squ.re/2Hks3YE
from react-square-payment-form.
Thanks for pointing me to the slack group! Turns out I might be able to do this with display: none
, though it does give a lot of warnings
ElementNotVisibleError: SqPaymentForm element with id 'sq-payment-form-sq-card-number' is not visible. Does it or a parent element have 'display:none'?
from react-square-payment-form.
Related Issues (20)
- Create Nonce outside of SquarePaymentForm Context
- paymentFormLoaded not being invoked properly HOT 1
- Allow calling `setPostalCode` after the payment form has loaded
- No way to change styling of the input field inside the iframe. HOT 1
- [TS] Wrong types for SqContact (in createVerificationDetails)
- npm install fails to fetch artifact
- sandox=false HOT 1
- Support Gift Card payment form HOT 1
- Payment form script loaded multiple times
- Uncaught AnalyticsParametersRequiredError: The Analytics library must be initialized with analyticsParameters to call verifyBuyer HOT 1
- Support calling setPostalCode HOT 1
- CVV Not auto completing when using CreditCardCVVInput HOT 3
- When trying to run the demo the card UI doesn't have input fields HOT 7
- Styling the input fields HOT 1
- Update docs to show how to customize the form HOT 3
- Typescript requires formId and apiWrapper properties to be set HOT 1
- Digital wallet methods stay as 'loading' in the context HOT 4
- Unable to add line items HOT 2
- disable prop for CreditCardSubmitButton HOT 1
- Expose SquarePaymentForm State as Context HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-square-payment-form.