Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <main class="container">
    <form id="app" data-apartments='[{ "price": "23000", "rooms": "12" }, { "price": "42000", "rooms": "32" }]'>
        <h1>
            Dynamic apartment forms
        </h1>
        <hr>
        <div class="row">
            <div class="col-xs-2">
                <button type="button" v-on:click="addNewApartment" class="btn btn-block btn-success">
                    Add +
                </button>
            </div>
            <div class="col-xs-10">
                Would you like add more apartments?
            </div>
        </div>
        <div v-for="(apartment, index) in apartments">
            <div class="row">
                <div class="col-xs-2">
                    <label>&nbsp;</label>
                    <button type="button" v-on:click="removeApartment(index)" class="btn btn-block btn-danger">
                        Rem -
                    </button>
                </div>
                <div class="form-group col-xs-5">
                    <label>Price (HUF)</label>
                    <input v-model="apartment.price" type="number"
                           name="apartments[][price]" class="form-control" placeholder="Price">
                </div>
                <div class="form-group col-xs-5">
                    <label>Rooms (PCS)</label>
                    <input v-model="apartment.rooms" type="number"
                           name="apartments[][rooms]" class="form-control" placeholder="Rooms">
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-xs-2">
                <button type="submit" v-on:click.prevent="sumbitForm" class="btn btn-block btn-primary">
                    Submit
                </button>
            </div>
            <div class="col-xs-10">
                Open the console (F12) and see the result
            </div>
        </div>
        <hr>
        <pre>{{ $data }}</pre>
    </form>
</main>
              
            
!

CSS

              
                
              
            
!

JS

              
                window.app = new Vue({
  el: '#app',
  data: {
    apartment: {
      price: '',
      rooms: ''
    },
    apartments: [],
  },
  mounted: function () {
    /*
     * The "data-apartments" could come from serverside (already saved apartments)
     */
    this.apartments = JSON.parse(this.$el.dataset.apartments)
  },
  methods: {
    addNewApartment: function () {
      this.apartments.push(Vue.util.extend({}, this.apartment))
    },
    removeApartment: function (index) {
      Vue.delete(this.apartments, index);
    },
    sumbitForm: function () {
      /*
       * You can remove or replace the "submitForm" method.
       * Remove: if you handle form sumission on server side.
       * Replace: for example you need an AJAX submission.
       */
      console.info('<< Form Submitted >>')
      console.info('Vue.js apartments object:', this.apartments)
      window.testSumbit()
    }
  }
})

/*
 * This is not Vue.js code, just a bit of jQuery to test what data would be submitted.
 */
window.testSumbit = function () {
  if (!window.jQuery) {
    console.warn('jQuery not present!')
    return false
  }
  console.info('Submitted (serverside) array:', jQuery('form').serializeJSON())
}
              
            
!
999px

Console