Skip to content

Commit

Permalink
Fixed small issues
Browse files Browse the repository at this point in the history
  • Loading branch information
choxnox committed Jul 17, 2017
1 parent eb31771 commit 30fa749
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 35 deletions.
21 changes: 13 additions & 8 deletions lib/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ Element.prototype.getFullyQualifiedName = function(HTMLnotation) {
{
name = name.replace(/\./, "[");
name = name.replace(/\./g, "][");
name += "]";

if (this.getBelongsTo())
name += "]";
}

if (this.getIsArray())
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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)
{
Expand All @@ -289,17 +294,17 @@ 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());
}
}
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
{
Expand All @@ -311,15 +316,15 @@ 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
});
}
else
{
var html = options.noRender ? elementString : jade.render(elementString);
html = options.noRender ? elementString : jade.render(elementString);
}

if (this.getError())
Expand Down Expand Up @@ -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 = []; };

Expand Down
33 changes: 7 additions & 26 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
{
Expand All @@ -388,17 +369,17 @@ 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());
}
}
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
{
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit 30fa749

Please sign in to comment.