diff --git a/lib/element.js b/lib/element.js index b742e27..7ea6392 100644 --- a/lib/element.js +++ b/lib/element.js @@ -56,7 +56,9 @@ Element.prototype.getFullyQualifiedName = function(HTMLnotation) { { name = name.replace(/\./, "["); name = name.replace(/\./g, "]["); - name += "]"; + + if (this.getBelongsTo()) + name += "]"; } if (this.getIsArray()) @@ -219,7 +221,7 @@ Element.prototype.render = function(callback, options) { }); var attribs = _.extend({ - name: this.getFullyQualifiedName(), + name: this.getFullyQualifiedName(true), id: this._options.attribs.id ? this._options.attribs.id : this._options.name }, this._options.attribs); @@ -274,11 +276,14 @@ Element.prototype.render = function(callback, options) { } var elementString = jadeString; + var html = ""; if (this.getViewScriptFile()) { var viewScriptPaths = []; var path = require("path"); + var i = 0; + var viewScriptPath = ""; var addSlash = function(path) { @@ -289,7 +294,7 @@ Element.prototype.render = function(callback, options) { { var viewPaths = this.getViewScriptPaths(); - for (var i = 0; i < this.getViewScriptPaths().length; i++) + for (i = 0; i < this.getViewScriptPaths().length; i++) { viewScriptPaths.push(addSlash(viewPaths[i]) + this.getViewScriptFile()); } @@ -297,9 +302,9 @@ Element.prototype.render = function(callback, options) { else viewScriptPaths.push(this.getViewScriptPaths()); - for (var i = 0; i < viewScriptPaths.length; i++) + for (i = 0; i < viewScriptPaths.length; i++) { - var viewScriptPath = viewScriptPaths[i]; + viewScriptPath = viewScriptPaths[i]; try { @@ -311,7 +316,7 @@ Element.prototype.render = function(callback, options) { var elementHtml = jade.render(jadeString); - var html = jade.renderFile(viewScriptPath, { + html = jade.renderFile(viewScriptPath, { element: this, elementHtml: elementHtml, data: this._options.viewScriptData @@ -319,7 +324,7 @@ Element.prototype.render = function(callback, options) { } else { - var html = options.noRender ? elementString : jade.render(elementString); + html = options.noRender ? elementString : jade.render(elementString); } if (this.getError()) @@ -372,7 +377,7 @@ Element.prototype.getViewScriptPaths = function() { return this._options.view Element.prototype.getViewScriptString = function() { return this._options.viewScriptString; }; Element.prototype.hasAttrib = function(name) { return !_.isUndefined(this._options.attribs[name]); }; -Element.prototype.hasError = function() { return (this._error != null); }; +Element.prototype.hasError = function() { return (this._error !== null); }; Element.prototype.removeValidators = function() { this._options.validators = []; }; diff --git a/lib/index.js b/lib/index.js index 8097481..725ebd1 100644 --- a/lib/index.js +++ b/lib/index.js @@ -287,28 +287,6 @@ Form.prototype.populate = function(values) { }; populateElements(this._elements); - - - /*_.forEach(this._elements, function(element) { - var val; - - if (element.getBelongsTo()) - { - if (_.isUndefined(values[element.getBelongsTo()]) || _.isUndefined(values[element.getBelongsTo()][element.getName()])) - val = null; - else - val = values[element.getBelongsTo()][element.getName()]; - } - else - { - if (_.isUndefined(values[element.getName()])) - val = null; - else - val = values[element.getName()]; - } - - element.setValue(val); - });*/ }; Form.prototype.removeElement = function(name) { @@ -373,11 +351,14 @@ Form.prototype.render = function(callback) { jadeString = " %%content%%"; var formHtml = jade.render(jadeString); + var compiledContent = ""; if ($this.getViewScriptFile()) { var viewScriptPaths = []; var path = require("path"); + var i = 0; + var viewScriptPath = ""; var addSlash = function(path) { @@ -388,7 +369,7 @@ Form.prototype.render = function(callback) { { var viewPaths = $this.getViewScriptPaths(); - for (var i = 0; i < $this.getViewScriptPaths().length; i++) + for (i = 0; i < $this.getViewScriptPaths().length; i++) { viewScriptPaths.push(addSlash(viewPaths[i]) + $this.getViewScriptFile()); } @@ -396,9 +377,9 @@ Form.prototype.render = function(callback) { else viewScriptPaths.push($this.getViewScriptFile()); - for (var i = 0; i < viewScriptPaths.length; i++) + for (i = 0; i < viewScriptPaths.length; i++) { - var viewScriptPath = viewScriptPaths[i]; + viewScriptPath = viewScriptPaths[i]; try { @@ -408,7 +389,7 @@ Form.prototype.render = function(callback) { catch (err) { } } - var compiledContent = jade.renderFile(viewScriptPath, { + compiledContent = jade.renderFile(viewScriptPath, { elements: $this._elements, subforms: $this._subforms, data: $this._options.viewScriptData diff --git a/package.json b/package.json index 6d7ed23..843f21d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "carbon-form", - "version": "0.1.24", + "version": "0.1.25", "description": "Provides Zend-like forms in Node.js", "homepage": "https://github.com/carbonjs/carbon-form", "author": {