css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div class="speech-bubble">
  <div id="bubble-title">
    NZ - Multiple widgets on one page
  </div>
  <div id="bubble-description">
    This example shows how it's possible to use two widgets to collect two different types of addresses within the same page. We are using a billing and shipping address form as an example. If you're looking for a more fully fledged version of this, look <a href="https://codepen.io/addressfinder/pen/aXGKde" target="_blank">HERE.<a>
  </div>
</div>

<form id="billing-form" class="form" method="get">
  <div id="form-title">Billing Address</div>
  
  <div class="form-header">Address Line 1</div>
  <input type="search" class="form-input" id="billing_addrs_1" placeholder="Search address here..."></input>
  
  <div class="form-header">Address Line 2</div>
  <input type="text" class="form-input" id="billing_addrs_2"></input>
  
  <div class="form-header">Suburb</div>
  <input type="text" class="form-input" id="billing_suburb"></input>
  
  <div class="form-header">City</div>
  <input class="form-input" id="billing_city"></input>
  
  <div class="form-header">Postcode</div>
  <input class="form-input" id="billing_postcode"></input>

  <input class="btn" type="submit" name="next" value="NEXT">
</form>    
    
<form class="form" method="get">
  <div id="form-title">Shipping Address</div>
  
  <div class="form-header">Address Line 1</div>
  <input type="search" class="form-input" id="mailing_addrs_1" placeholder="Search address here..."></input>
  
  <div class="form-header">Address Line 2</div>
  <input type="text" class="form-input" id="mailing_addrs_2"></input>
  
  <div class="form-header">Suburb</div>
  <input type="text" class="form-input" id="mailing_suburb"></input>
  
  <div class="form-header">City</div>
  <input class="form-input" id="mailing_city"></input>
  
  <div class="form-header">Postcode</div>
  <input class="form-input" id="mailing_postcode"></input>

  <input class="btn" type="submit" name="next" value="NEXT">
  
</form>


            
          
!
            
              @import url('https://fonts.googleapis.com/css?family=Open+Sans');

html, body {
  padding: 1em 1.5em;
  font-family: 'Open Sans', Arial, Helvetica, sans-serif;
  font-size: 15px;
  width: 1500px;
  color: #6d6d6d;
}

.speech-bubble {
  position: relative;
  padding: 1.5em;
  border-radius: 10px;
  box-sizing: border-box;
  background: #eaf5fa;
  box-shadow: 0px 2px 15px 0 rgba(0, 0, 0, 0.4);
  margin-bottom: 40px;
  width: 809px;
  margin-left: calc(360px);
}

.speech-bubble::before {
  content: "";
  position: absolute;
  width: 0;
  height: 0;
  bottom: -2em;
  left: 42.5%;
  box-sizing: border-box;
  border: 1em solid black;
  border-color: transparent transparent #eaf5fa #eaf5fa;
  transform-origin: 0 0;
  transform: rotate(-45deg);
  box-shadow: -4px 4px 5px 0 rgba(0, 0, 0, 0.2);;
  z-index: 0;
}

#bubble-title {
  font-size: 1.3em;
  margin-bottom: 8px;
}

.form {
  height: content;
  padding: 2em 3.5em;
  border-top: 50px solid #E8E8E8;
  border-left: 2px solid #E8E8E8;
  border-right: 2px solid #E8E8E8;
  border-bottom: 2px solid #E8E8E8;
  width: 600px;
  display: inline-block;
}

#billing-form {
  margin-right: 25px;
}

#form-title {
  font-size: 1.6em;
  padding-bottom: 6px;
  margin-bottom: 25px;
  border-bottom: 1.5px solid #E8E8E8;
}

.form-header {
  font-size: 16px;
  margin-bottom: 2px;
}

.form-input {
  width: 70%;
  height: 30px;
  font-size: 16px;
  padding-left: 6px;
}

.form-input:not(:last-child) {
  margin-bottom: 15px;
}

input[type=submit] {
  display: block;
  -webkit-appearance: button;
  font-size: 15px;
  width: 135px;
  height: 36px;
  margin-left: 296px;
  background-color: #E18988;
  color: #FFFFFF;
  border: none;
  border-radius: 3px;
}

/* Forces .form-input styles onto search type */
input[type=search] {
  -webkit-appearance: textfield;
  box-sizing: content-box;
}


            
          
!
            
              (function(d){
  var billing_addressfield = d.getElementById('billing_addrs_1'),
      mailing_addressfield = d.getElementById('mailing_addrs_1'),
      API_KEY = 'ADDRESSFINDER_DEMO_KEY',
      widgets = {
        mailing: null,
        billing: null
      };
  
  function attachAutoFillFields(widget, prefix) {
    widget.on('result:select', function(fullAddress, metaData) {
      var selected = new AddressFinder.NZSelectedAddress(fullAddress, metaData);
      
      // You will need to update these ids to match those in your form
      document.getElementById(prefix + '_addrs_1').value = selected.address_line_1();
      document.getElementById(prefix + '_addrs_2').value = selected.address_line_2();
      document.getElementById(prefix + '_suburb').value = selected.suburb();
      document.getElementById(prefix + '_city').value = selected.city();
      document.getElementById(prefix + '_postcode').value = selected.postcode();
    });
  }

  function initAF(){
    widgets['billing'] = new AddressFinder.Widget(
      billing_addressfield,
      API_KEY,
      'NZ', {
        "address_params": {
          "delivered": "1"
        }
      }
    );
    attachAutoFillFields(widgets['billing'], 'billing')
    
    widgets['mailing'] = new AddressFinder.Widget(
      mailing_addressfield,
      API_KEY,
      'NZ', {
        "address_params": {
          "post_box": "0"
        }
      }
    );
    attachAutoFillFields(widgets['mailing'], 'mailing')
  }

  function addScript(){
    var script = document.createElement('script');
    script.src = 'https://api.addressfinder.io/assets/v3/widget.js';
    script.async = true;
    script.onload = initAF;
    document.body.appendChild(script);
  }

  // Initialise
  addScript();

})(document);

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console