diff --git a/README.md b/README.md
index 5180a5e..f396496 100644
--- a/README.md
+++ b/README.md
@@ -17,9 +17,10 @@ So far, we support the following json schema types:
* string
* boolean
* enum
+* email
* integer
-* required
* number
+* required
* pattern
We aim to eventually support:
diff --git a/app/js/schemaFormField.js.coffee b/app/js/schemaFormField.js.coffee
index c63b181..456f021 100644
--- a/app/js/schemaFormField.js.coffee
+++ b/app/js/schemaFormField.js.coffee
@@ -22,6 +22,7 @@ angular.module("schemaForm").directive "schemaFormField", ($compile, $templateCa
template = $templateCache.get("enumField.html") if scope.schema.enum?
element.html template
element.find("input").attr("type", "number") if (scope.schema.type == "number" or scope.schema.type == "integer")
+ element.find("input").attr("type", "email") if scope.schema.type == "email"
element.find("input").attr("ng-required", scope.required)
element.find("input").attr("ng-pattern", "/#{scope.schema.pattern}/") if scope.schema.pattern
element.find("input").attr("name", scope.field)
diff --git a/app/templates/emailField.html b/app/templates/emailField.html
new file mode 100644
index 0000000..7294ca5
--- /dev/null
+++ b/app/templates/emailField.html
@@ -0,0 +1,4 @@
+
+
+
+
diff --git a/config/application.js b/config/application.js
index b04ba75..cb6deb8 100644
--- a/config/application.js
+++ b/config/application.js
@@ -16,17 +16,12 @@ module.exports = function(lineman) {
var app = lineman.config.application;
return {
- concat: {
- uncompressedDist: {
- src: app.concat.uncompressedDist.src.concat("<%= files.ngtemplates.dest %>")
- }
- },
ngtemplates: {
options: {
module: "schemaForm"
}
},
-
+
appendTasks: {
dev: app.appendTasks.dev.concat("server")
}
diff --git a/config/application.json b/config/application.json
new file mode 100644
index 0000000..4283f51
--- /dev/null
+++ b/config/application.json
@@ -0,0 +1,8 @@
+{
+ "plugins": {
+ "lib": {
+ "includeVendorInDistribution": false,
+ "generateBowerJson": true
+ }
+ }
+}
\ No newline at end of file
diff --git a/config/lib.json b/config/lib.json
deleted file mode 100644
index 2041926..0000000
--- a/config/lib.json
+++ /dev/null
@@ -1,4 +0,0 @@
-{
- "includeVendorInDistribution": false,
- "generateBowerJson": true
-}
diff --git a/dist/schema-form.js b/dist/schema-form.js
index 2f005f1..13d878d 100644
--- a/dist/schema-form.js
+++ b/dist/schema-form.js
@@ -21,13 +21,28 @@
editAs: "@"
},
link: function(scope, element, attrs, formController) {
- var template;
+ var template, typeTemplates;
+ typeTemplates = {
+ bool: 'boolean',
+ boolean: 'boolean',
+ email: 'email',
+ "enum": 'enum',
+ integer: 'string',
+ number: 'string',
+ string: 'string'
+ };
scope.formState = formController;
- template = scope.schema["enum"] != null ? $templateCache.get("enumField.html") : $templateCache.get("" + scope.schema.type + "Field.html");
+ template = $templateCache.get("" + typeTemplates[scope.schema.type] + "Field.html");
+ if (scope.schema["enum"] != null) {
+ template = $templateCache.get("enumField.html");
+ }
element.html(template);
if (scope.schema.type === "number" || scope.schema.type === "integer") {
element.find("input").attr("type", "number");
}
+ if (scope.schema.type === "email") {
+ element.find("input").attr("type", "email");
+ }
element.find("input").attr("ng-required", scope.required);
if (scope.schema.pattern) {
element.find("input").attr("ng-pattern", "/" + scope.schema.pattern + "/");
@@ -59,37 +74,3 @@
});
}).call(this);
-
-angular.module("schemaForm").run(["$templateCache", function($templateCache) {
-
- $templateCache.put("booleanField.html",
- "\n" +
- " \n" +
- " \n" +
- "
\n"
- );
-
- $templateCache.put("enumField.html",
- "\n" +
- " \n" +
- " \n" +
- "
\n"
- );
-
- $templateCache.put("schemaFormFields.html",
- "\n" +
- " \n" +
- " \n" +
- "
\n"
- );
-
- $templateCache.put("stringField.html",
- "\n" +
- " \n" +
- " \n" +
- "
\n"
- );
-
-}]);
diff --git a/dist/schema-form.min.js b/dist/schema-form.min.js
index bd0cc43..bffc7ec 100644
--- a/dist/schema-form.min.js
+++ b/dist/schema-form.min.js
@@ -2,4 +2,4 @@
* Angular directives that produces form fields from json schema
* https://your/lib/name/here
*/
-(function(){angular.module("schemaForm",[])}).call(this),function(){angular.module("schemaForm").directive("schemaFormField",function(a,b){return{restrict:"EA",replace:!0,require:"^form",scope:{schema:"=",model:"=",field:"=",required:"=",editAs:"@"},link:function(c,d,e,f){var g;return c.formState=f,g=b.get(null!=c.schema["enum"]?"enumField.html":""+c.schema.type+"Field.html"),d.html(g),("number"===c.schema.type||"integer"===c.schema.type)&&d.find("input").attr("type","number"),d.find("input").attr("ng-required",c.required),c.schema.pattern&&d.find("input").attr("ng-pattern","/"+c.schema.pattern+"/"),d.find("input").attr("name",c.field),a(d.contents())(c)}}})}.call(this),function(){angular.module("schemaForm").directive("schemaFormFields",function(){return{restrict:"EA",scope:{schema:"=",model:"=",fields:"="},link:function(a){return a.required=function(a){return _.contains(this.schema.required,a)}},templateUrl:"schemaFormFields.html"}})}.call(this),angular.module("schemaForm").run(["$templateCache",function(a){a.put("booleanField.html",'\n \n \n
\n'),a.put("enumField.html",'\n \n \n
\n'),a.put("schemaFormFields.html",'\n \n \n
\n'),a.put("stringField.html",'\n \n \n
\n')}]);
\ No newline at end of file
+(function(){angular.module("schemaForm",[])}).call(this),function(){angular.module("schemaForm").directive("schemaFormField",function(a,b){return{restrict:"EA",replace:!0,require:"^form",scope:{schema:"=",model:"=",field:"=",required:"=",editAs:"@"},link:function(c,d,e,f){var g,h;return h={bool:"boolean","boolean":"boolean",email:"email","enum":"enum",integer:"string",number:"string",string:"string"},c.formState=f,g=b.get(""+h[c.schema.type]+"Field.html"),null!=c.schema["enum"]&&(g=b.get("enumField.html")),d.html(g),("number"===c.schema.type||"integer"===c.schema.type)&&d.find("input").attr("type","number"),"email"===c.schema.type&&d.find("input").attr("type","email"),d.find("input").attr("ng-required",c.required),c.schema.pattern&&d.find("input").attr("ng-pattern","/"+c.schema.pattern+"/"),d.find("input").attr("name",c.field),a(d.contents())(c)}}})}.call(this),function(){angular.module("schemaForm").directive("schemaFormFields",function(){return{restrict:"EA",scope:{schema:"=",model:"=",fields:"="},link:function(a){return a.required=function(a){return _.contains(this.schema.required,a)}},templateUrl:"schemaFormFields.html"}})}.call(this);
\ No newline at end of file
diff --git a/example.js b/example.js
index 3b601b4..64b23f5 100644
--- a/example.js
+++ b/example.js
@@ -3,7 +3,7 @@ var app = angular.module("app", ["schemaForm"]);
app.controller("ExampleCtrl", function($scope) {
$scope.schema =
{
- title: "Thing"
+ title: "Thing",
type: "object",
properties: {
title: {
@@ -16,14 +16,26 @@ app.controller("ExampleCtrl", function($scope) {
title: "Good?"
},
level: {
- title: "Level",
type: "string",
+ title: "Level",
enum: ["low", "medium", "high"]
+ },
+ number: {
+ type: "number",
+ title: "What's your lucky number?",
+ },
+ integer: {
+ type: "integer",
+ title: "Integer too"
+ },
+ user_email: {
+ type: "email",
+ title: "Email por favor"
}
},
required: ["title"]
}
- $scope.fields = ["title", "level", "good"]
+ $scope.fields = ["title", "level", "good", "number", "integer", "user_email"]
$scope.model = {
title: "Uncle John's Bathroom Reader",
good: false