Nested form(React)

by VeryGoodFiddle

HTML

<script src="https://js.verygoodvault.io/vgs-collect/1/vgs-collect-examples.js"></script>
<div id="app"></div>

CSS

body {
  background: #20262E;
  padding: 20px;
  font-family: Helvetica;
}

form {
  margin-bottom: 10px;
}

#app {
  background: #fff;
  border-radius: 4px;
  padding: 20px;
  transition: all 0.2s;
}

label {
  font-size: 12px;
  display: block;
}

.fake-input iframe, input {
  height: 32px;
  max-width: 100%;
  border: solid 1px #ccc;
  border-radius: 4px;
  padding-left: 4px;
  margin-bottom: 5px;
}

input {
  margin-bottom: 5px;
  height: 30px;
}

React

class CheckoutForm extends React.Component {
  constructor(props) {
    super(props);
    this.form = {};
    this.paymentAmount = React.createRef();
    this.cardFee = React.createRef();
    this.handleSubmit = this.handleSubmit.bind(this);
  }
  
  componentDidMount() {
  	this.form = VGSCollect.create('tntq4dwvhri', function(state) {});
  	
    this.form.field('#cc-name .fake-input', {
      type: 'text',
      name: 'card.name',
      placeholder: 'Joe Business',
      validations: ['required'],
		});

    this.form.field('#cc-number .fake-input', {
      type: 'card-number',
      name: 'card.number',
      successColor: '#4F8A10',
      errorColor: '#D8000C',
      placeholder: '4111 1111 1111 1111',
      validations: ['required', 'validCardNumber'],
    });

    this.form.field('#cc-cvc .fake-input', {
      type: 'card-security-code',
      name: 'card.cvc',
      placeholder: '344',
      validations: ['required', 'validCardSecurityCode'],
    });

    this.form.field('#cc-expiration-date .fake-input', {
      type: 'card-expiration-date',
      name: 'card.expirationDate',
      placeholder: '01 / 20',
      serializers: [this.form.SERIALIZERS.separate({monthName: 'month', yearName: 'year'})],
      validations: ['required', 'validCardExpirationDate']
		});
  }
  
  handleSubmit(e){
  	e.preventDefault();
  	this.form.submit('/post', {
    	data: {
      	paymentAmount: this.paymentAmount.current.value,
        debitCardFee: this.cardFee.current.value,
      }
    }, function(status, response) {
    	document.getElementById('card-preview').innerText = JSON.stringify(response.json, null, ' ');
    });
  }
  
  render() {
    return (
    <div>
      <form onSubmit={this.handleSubmit}>
      <div className="form-group">
         <label htmlFor="amount">Payment amount</label>
         <input type="number" id="amount" className="form-control" ref={this.paymentAmount}/>   
      </div>
      <div id="cc-number" className="form-group">
        <div...