Permalink
Browse files

add a new feature to form generator, and update readme

add feature to support TextArea and Checkbox for fields based on
property type
  • Loading branch information...
1 parent f77c7bf commit ddc02bc20db271d4c59980ce89175117533d085c Geeknux committed Feb 27, 2012
Showing with 16 additions and 18 deletions.
  1. +8 −13 README.md
  2. +8 −5 index.js
View
@@ -7,20 +7,15 @@ This Modules is for Jugglingdb and written for express-on-railway framework.
https://github.com/1602/express-on-railway
## Features
-1- extend properties, add "Lable", "Comment", "Class", "Style".
-
-2- use custom widget for field, by binding the property to a custom function.
-
-3- generate form on-the fly.
-
-4- using form generator as an Insert or Update form.
-
-5- set custom value for submit button.
+* extend properties, add "Lable", "Comment", "Class", "Style".
+* use custom widget for field, by binding the property to a custom function.
+* generate form on-the fly.
+* using form generator as an Insert or Update form.
+* set custom value for submit button.
## TO-DO
-1- add tabless feature.
-
-2- add xhr (ajax) request .
+* add tabless feature.
+* add xhr (ajax) request .
## Usage
@@ -44,7 +39,7 @@ Step 2. Extend your Schema;
Person.extProperty({
email: {label: 'Enter your Email:', comment: 'e.g: john.smith@gmail.com'},
name: {label: 'Enter your Full Name:', comment: 'e.g: John Smith'},
- gender: {label: 'Gender:', comment: '"Male" or "Femail"', style:'width: 40px'}
+ gender: {label: 'Gender:', comment: '"Male" or "Female"', style:'width: 40px'}
});
```
View
@@ -12,7 +12,6 @@
exports.init = function () {
// add orm method
- // this extention is based on jugglingdb which is used in Express-on-Railway framework
railway.orm.AbstractClass.extProperty = extendProperty;
railway.orm.AbstractClass.FormSchema = generate_form;
@@ -27,7 +26,6 @@ exports.init = function () {
*/
function extendProperty(obj) {
var model = this.schema.definitions[this.modelName];
- //console.log('DS:' + model.properties['img'].type.name);
if(typeof obj === 'object') {
Object.keys(obj).forEach(function (o) {
@@ -82,8 +80,7 @@ function generate_form(info, data, fields) {
return output;
} catch (err) {
- console.log(err);
- return err;
+ throw new Error(err);
}
}
@@ -133,7 +130,13 @@ function getForm(formSchema, extData, request) {
if(typeof properties[prop]['widget'] === 'function') {
output += properties[prop]['widget'](prop, properties[prop]['value']);
} else {
- output += util.format('<input type="text" id="%s" name="%s" value="%s" class="text%s" %s />', prop, prop, properties[prop]['value'], (properties[prop]['class']) ? ' ' + properties[prop]['class'] : '', (properties[prop]['style']) ? ' style="' + properties[prop]['style'] + '"' : '');
+ if(properties[prop].type.name === 'Text') {
+ output += util.format('<textarea id="%s" name="%s" class="text%s" %s>%s</textarea>', prop, prop, (properties[prop]['class']) ? ' ' + properties[prop]['class'] : '', (properties[prop]['style']) ? ' style="' + properties[prop]['style'] + '"' : '', properties[prop]['value']);
+ } else if (properties[prop].type.name === 'Boolean') {
+ output += util.format('<input type="checkbox" id="%s" name="%s" class="text%s" %s%s />', prop, prop, (properties[prop]['class']) ? ' ' + properties[prop]['class'] : '', (properties[prop]['style']) ? ' style="' + properties[prop]['style'] + '"' : '', (properties[prop]['value']) ? ' CHECKED' : '');
+ } else {
+ output += util.format('<input type="text" id="%s" name="%s" value="%s" class="text%s" %s />', prop, prop, properties[prop]['value'], (properties[prop]['class']) ? ' ' + properties[prop]['class'] : '', (properties[prop]['style']) ? ' style="' + properties[prop]['style'] + '"' : '');
+ }
}
output += '</td>';

0 comments on commit ddc02bc

Please sign in to comment.