Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swell.payment.createElements does not respect seperateElements option #98

Open
VojtaSim opened this issue Mar 30, 2023 · 2 comments
Open

Comments

@VojtaSim
Copy link

I'd like to render separate elements for card's number, expiration and CVC. However when I use config for swell.payment.createElements mentioned in official docs it does not respect seperateElements option.

In browser I get this error message:

The selector you specified (#card-element) applies to no DOM elements that are currently on the page.
Make sure the element exists on the page before calling mount().

When I specify elementId directly for card and use it without !seperateElements: true` it works.

useEffect(() => {
    swell.payment.createElements({
      card: {
        seperateElements: true,
        cardNumber: {
          elementId: '#card-number',
        },
        cardExpiry: {
          elementId: '#card-expiry',
        },
        cardCvc: {
          elementId: '#card-cvc',
        }
      }
    })
  }, [])

return (
  <label>
    <span className="copy">Card Number</span>
    <div id="card-number" />
  </label>
  <div className="flex flex-between gap-20">
    <label className="flex-1">
      <span className="copy">Card Expiry</span>
      <div id="card-expiry" />
    </label>
    <label className="flex-1">
      <span className="copy">CVC</span>
      <div id="card-cvc" />
    </label>
  </div>
)
@VojtaSim VojtaSim changed the title swell.payment.createElements does not respect seperateElements option swell.payment.createElements does not respect seperateElements option Mar 30, 2023
@vstudenichnik-insoft
Copy link
Contributor

vstudenichnik-insoft commented Apr 3, 2023

Hi @VojtaSim, we are working on a fix. As a temporary workaround, you can replace the DOM element IDs like this:

<div id="cardNumber-element" />
<div id="cardExpiry-element" />
<div id="cardCvc-element" />

@VojtaSim
Copy link
Author

VojtaSim commented Apr 6, 2023

I pushed PR with the fix #99

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants