Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

stripe registerElement not defined

Tags:

javascript

I am trying to use Example2 from stripe

my jscript is

<script src="https://js.stripe.com/v3/"></script>
<script>
      var stripe = Stripe('test key');
      var elements = stripe.elements();
      example2.js per link above
</script>

I am getting an error on the last line of example2.js

registerElements([cardNumber, cardExpiry, cardCvc], 'example2'); (Not Defined)

Suggestions welcome.. thanks

like image 967
clarence_odbody Avatar asked Nov 28 '17 21:11

clarence_odbody


2 Answers

I just realized that - in 2021 - GitHub can do this :

enter image description here

like image 56
pszaba Avatar answered Nov 14 '22 22:11

pszaba


You're right, there's a bug in the repo... You can fix it by importing the function from here

function registerElements(elements, exampleName) {
  var formClass = '.' + exampleName;
  var example = document.querySelector(formClass);

  var form = example.querySelector('form');
  var resetButton = example.querySelector('a.reset');
  var error = form.querySelector('.error');
  var errorMessage = error.querySelector('.message');

  function enableInputs() {
    Array.prototype.forEach.call(
      form.querySelectorAll(
        "input[type='text'], input[type='email'], input[type='tel']"
      ),
      function(input) {
        input.removeAttribute('disabled');
      }
    );
  }

You should submit an issue to the owner of the repo here

like image 8
Natalie Avatar answered Nov 14 '22 21:11

Natalie