      if(this.schema.type && typeof this.schema.type === "string") this.container.setAttribute('data-schematype',this.schema.type);
      this.container.setAttribute('data-schemapath',this.path);
    },
-@@ -1754,7 +1820,13 @@
+-  
++
+   preBuild: function() {
+ 
+   },
+   build: function() {
+-    
++
+   },
+   postBuild: function() {
+     this.setupWatchListeners();
+@@ -1450,10 +1516,10 @@
+     this.register();
+     this.onWatchedFieldChange();
+   },
+-  
++
+   setupWatchListeners: function() {
+     var self = this;
+-    
++
+     // Watched fields
+     this.watched = {};
+     if(this.schema.vars) this.schema.watch = this.schema.vars;
+@@ -1463,7 +1529,7 @@
+         self.onWatchedFieldChange();
+       }
+     };
+-    
++
+     this.register();
+     if(this.schema.hasOwnProperty('watch')) {
+       var path,path_parts,first,root,adjusted_path;
+@@ -1489,19 +1555,19 @@
+ 
+         // Keep track of the root node and path for use when rendering the template
+         adjusted_path = root.getAttribute('data-schemapath') + '.' + path_parts.join('.');
+-        
++
+         self.jsoneditor.watch(adjusted_path,self.watch_listener);
+-        
++
+         self.watched[name] = adjusted_path;
+       }
+     }
+-    
++
+     // Dynamic header
+     if(this.schema.headerTemplate) {
+       this.header_template = this.jsoneditor.compileTemplate(this.schema.headerTemplate, this.template_engine);
+     }
+   },
+-  
++
+   addLinks: function() {
+     // Add links
+     if(!this.no_link_holder) {
+@@ -1514,18 +1580,18 @@
+       }
+     }
+   },
+-  
+-  
++
++
+   getButton: function(text, icon, title) {
+     var btnClass = 'json-editor-btn-'+icon;
+     if(!this.iconlib) icon = null;
+     else icon = this.iconlib.getIcon(icon);
+-    
++
+     if(!icon && title) {
+       text = title;
+       title = null;
+     }
+-    
++
+     var btn = this.theme.getButton(text, icon, title);
+     btn.className += ' ' + btnClass + ' ';
+     return btn;
+@@ -1533,12 +1599,12 @@
+   setButtonText: function(button, text, icon, title) {
+     if(!this.iconlib) icon = null;
+     else icon = this.iconlib.getIcon(icon);
+-    
++
+     if(!icon && title) {
+       text = title;
+       title = null;
+     }
+-    
++
+     return this.theme.setButtonText(button, text, icon, title);
+   },
+   addLink: function(link) {
+@@ -1546,11 +1612,11 @@
+   },
+   getLink: function(data) {
+     var holder, link;
+-        
++
+     // Get mime type of the link
+     var mime = data.mediaType || 'application/javascript';
+     var type = mime.split('/')[0];
+-    
++
+     // Template to generate the link href
+     var href = this.jsoneditor.compileTemplate(data.href,this.template_engine);
+ 
+@@ -1568,10 +1634,10 @@
+       link = document.createElement('a');
+       link.setAttribute('target','_blank');
+       var image = document.createElement('img');
+-      
++
+       this.theme.createImageLink(holder,link,image);
+-    
+-      // When a watched field changes, update the url  
++
++      // When a watched field changes, update the url
+       this.link_watchers.push(function(vars) {
+         var url = href(vars);
+         link.setAttribute('href',url);
+@@ -1582,16 +1648,16 @@
+     // Audio/Video links
+     else if(['audio','video'].indexOf(type) >=0) {
+       holder = this.theme.getBlockLinkHolder();
+-      
++
+       link = this.theme.getBlockLink();
+       link.setAttribute('target','_blank');
+-      
++
+       var media = document.createElement(type);
+       media.setAttribute('controls','controls');
+-      
++
+       this.theme.createMediaLink(holder,link,media);
+-      
+-      // When a watched field changes, update the url  
++
++      // When a watched field changes, update the url
+       this.link_watchers.push(function(vars) {
+         var url = href(vars);
+         link.setAttribute('href',url);
+@@ -1631,7 +1697,7 @@
+     var watched = {};
+     var changed = false;
+     var self = this;
+-    
++
+     if(this.watched) {
+       var val,editor;
+       for(var name in this.watched) {
+@@ -1642,12 +1708,12 @@
+         watched[name] = val;
+       }
+     }
+-    
++
+     watched.self = this.getValue();
+     if(this.watched_values.self !== watched.self) changed = true;
+-    
++
+     this.watched_values = watched;
+-    
++
+     return changed;
+   },
+   getWatchedFieldValues: function() {
+@@ -1677,7 +1743,7 @@
+   },
+   onWatchedFieldChange: function() {
+     var vars;
+-    if(this.header_template) {      
++    if(this.header_template) {
+       vars = $extend(this.getWatchedFieldValues(),{
+         key: this.key,
+         i: this.key,
+@@ -1686,7 +1752,7 @@
+         title: this.getTitle()
+       });
+       var header_text = this.header_template(vars);
+-      
++
+       if(header_text !== this.header_text) {
+         this.header_text = header_text;
+         this.updateHeaderText();
+@@ -1736,12 +1802,12 @@
+   getDefault: function() {
+     if(this.schema["default"]) return this.schema["default"];
+     if(this.schema["enum"]) return this.schema["enum"][0];
+-    
++
+     var type = this.schema.type || this.schema.oneOf;
+     if(type && Array.isArray(type)) type = type[0];
+     if(type && typeof type === "object") type = type.type;
+     if(type && Array.isArray(type)) type = type[0];
+-    
++
+     if(typeof type === "string") {
+       if(type === "number") return 0.0;
+       if(type === "boolean") return false;
+@@ -1750,11 +1816,17 @@
+       if(type === "object") return {};
+       if(type === "array") return [];
+     }
+-    
++
      return null;
    },
    getTitle: function() {

         e.preventDefault();
         e.stopPropagation();
         if(self.addproperty_input.value) {
@@ -2677,6 +2800,7 @@
           }
           self.onChange(true);
         }

     window.requestAnimationFrame(function() {
       self.firing_change = false;
       if(!self.ready) return;
 
       // Validate and cache results
       self.validation_results = self.validator.validate(self.root.getValue());
-      
+
       if(self.options.show_errors !== "never") {
         self.root.showValidationErrors(self.validation_results);
       }
       else {
         self.root.showValidationErrors([]);
       }
-      
+
       // Fire change event
       self.trigger('change');
     });
-    
+
     return this;
   },
   compileTemplate: function(template, name) {
@@ -475,7 +540,7 @@
     else {
       // No data stored
       if(!el.hasAttribute('data-jsoneditor-'+key)) return null;
-      
+
       return this.__data[el.getAttribute('data-jsoneditor-'+key)];
     }
   },
@@ -497,7 +562,7 @@
     this.watchlist = this.watchlist || {};
     this.watchlist[path] = this.watchlist[path] || [];
     this.watchlist[path].push(callback);
-    
+
     return this;
   },
   unwatch: function(path,callback) {
@@ -507,7 +572,7 @@
       this.watchlist[path] = null;
       return this;
     }
-    
+
     var newlist = [];
     for(var i=0; i<this.watchlist[path].length; i++) {
       if(this.watchlist[path][i] === callback) continue;
@@ -552,11 +617,11 @@
         }
       }
     };
-    
+
     if(schema.$ref && typeof schema.$ref !== "object" && schema.$ref.substr(0,1) !== "#" && !this.refs[schema.$ref]) {
       refs[schema.$ref] = true;
     }
-    
+
     for(var i in schema) {
       if(!schema.hasOwnProperty(i)) continue;
       if(schema[i] && typeof schema[i] === "object" && Array.isArray(schema[i])) {
@@ -570,25 +635,25 @@
         merge_refs(this._getExternalRefs(schema[i]));
       }
     }
-    
+
     return refs;
   },
   _loadExternalRefs: function(schema, callback) {
     var self = this;
     var refs = this._getExternalRefs(schema);
-    
+
     var done = 0, waiting = 0, callback_fired = false;
-    
+
     $each(refs,function(url) {
       if(self.refs[url]) return;
       if(!self.options.ajax) throw "Must set ajax option to true to load external ref "+url;
       self.refs[url] = 'loading';
       waiting++;
 
-      var r = new XMLHttpRequest(); 
+      var r = new XMLHttpRequest();
       r.open("GET", url, true);
       r.onreadystatechange = function () {
-        if (r.readyState != 4) return; 
+        if (r.readyState != 4) return;
         // Request succeeded
         if(r.status === 200) {
           var response;
@@ -600,7 +665,7 @@
             throw "Failed to parse external ref "+url;
           }
           if(!response || typeof response !== "object") throw "External ref does not contain a valid schema - "+url;
-          
+
           self.refs[url] = response;
           self._loadExternalRefs(response,function() {
             done++;
@@ -618,20 +683,20 @@
       };
       r.send();
     });
-    
+
     if(!waiting) {
       callback();
     }
   },
   expandRefs: function(schema) {
     schema = $extend({},schema);
-    
+
     while (schema.$ref) {
       var ref = schema.$ref;
       delete schema.$ref;
-      
+
       if(!this.refs[ref]) ref = decodeURIComponent(ref);
-      
+
       schema = this.extendSchemas(schema,this.refs[ref]);
     }
     return schema;
@@ -691,7 +756,7 @@
     if(schema.not) {
       schema.not = this.expandSchema(schema.not);
     }
-    
+
     // allOf schemas should be merged into the parent
     if(schema.allOf) {
       for(i=0; i<schema.allOf.length; i++) {
@@ -721,7 +786,7 @@
         extended.oneOf[i] = this.extendSchemas(this.expandSchema(schema.oneOf[i]),tmp);
       }
     }
-    
+
     return this.expandRefs(extended);
   },
   extendSchemas: function(obj1, obj2) {
@@ -1406,41 +1471,42 @@
   },
   init: function(options) {
     this.jsoneditor = options.jsoneditor;
-    
+
     this.theme = this.jsoneditor.theme;
     this.template_engine = this.jsoneditor.template;
     this.iconlib = this.jsoneditor.iconlib;
-    
+
     this.translate = this.jsoneditor.translate || JSONEditor.defaults.translate;
 
     this.original_schema = options.schema;
     this.schema = this.jsoneditor.expandSchema(this.original_schema);
-    
+
     this.options = $extend({}, (this.options || {}), (options.schema.options || {}), options);
-    
+
     if(!options.path && !this.schema.id) this.schema.id = 'root';
     this.path = options.path || 'root';
     this.formname = options.formname || this.path.replace(/\.([^.]+)/g,'[$1]');
     if(this.jsoneditor.options.form_name_root) this.formname = this.formname.replace(/^root\[/,this.jsoneditor.options.form_name_root+'[');
     this.key = this.path.split('.').pop();
     this.parent = options.parent;
-    
+
     this.link_watchers = [];
-    
+
     if(options.container) this.setContainer(options.container);
   },
   setContainer: function(container) {
     this.container = container;
     if(this.schema.id) this.container.setAttribute('data-schemaid',this.schema.id);
