var app = angular.module('plunker', ['schemaForm']);
app.controller('MainCtrl', function($scope) {
$scope.name = 'World';
$scope.model = {};
$scope.schema = {
"type": "object",
"properties": {
"s4_0": {
"type": "array",
"title": "CHECKBOXES",
"items": {
"type": "string",
"enum": [
1,
2,
3
]
}
}
}
};
$scope.form = [
{
"key": "s4_0",
"type": "checkboxes",
"titleMap": [
{
"value": "1",
"name": "box 1"
},
{
"value": "2",
"name": "box 3"
},
{
"value": "3",
"name": "box 2"
}
]
},
{
"type": "submit",
"title": "Submit"
}
];
$scope.onSubmit = function(form) {
// First we broadcast an event so all fields validate themselves
$scope.$broadcast('schemaFormValidate');
// Then we check if the form is valid
if (form.$valid) {
console.log("form is ", form);
console.log("model is ", $scope.model);
}
}
});
<!DOCTYPE html>
<html ng-app="plunker">
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<script>document.write('<base href="' + document.location + '" />');</script>
<link rel="stylesheet" href="style.css" />
<script data-require="jquery@*" data-semver="3.0.0" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.js"></script>
<script data-require="angular.js@1.4.x" src="https://code.angularjs.org/1.4.9/angular.js" data-semver="1.4.9"></script>
<script data-require="ui-router@*" data-semver="1.0.0-alpha.5" src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-router/1.0.0-alpha.5/angular-ui-router.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-sanitize/1.5.7/angular-sanitize.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tv4/1.2.7/tv4.min.js"></script>
<script src="ObjectPath.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-schema-form/0.8.13/schema-form.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-schema-form/0.8.13/bootstrap-decorator.min.js"></script>
<link data-require="bootstrap-css@3.3.6" data-semver="3.3.6" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.css" />
<script src="app.js"></script>
</head>
<body ng-controller="MainCtrl">
<p>Hello {{name}}!</p>
<form name="myForm"
sf-schema="schema"
sf-form="form"
sf-model="model"
ng-submit="onSubmit(myForm)"></form>
</body>
</html>
/* Put your css in here */
'use strict';
;!function(undefined) {
var ObjectPath = {
parse: function(str){
if(typeof str !== 'string'){
throw new TypeError('ObjectPath.parse must be passed a string');
}
var i = 0;
var parts = [];
var d, b, q, c;
while (i < str.length){
d = str.indexOf('.', i);
b = str.indexOf('[', i);
// we've reached the end
if (d === -1 && b === -1){
parts.push(str.slice(i, str.length));
i = str.length;
}
// dots
else if (b === -1 || (d !== -1 && d < b)) {
parts.push(str.slice(i, d));
i = d + 1;
}
// brackets
else {
if (b > i){
parts.push(str.slice(i, b));
i = b;
}
q = str.slice(b+1, b+2);
if (q !== '"' && q !=='\'') {
c = str.indexOf(']', b);
if (c === -1) c = str.length;
parts.push(str.slice(i + 1, c));
i = (str.slice(c + 1, c + 2) === '.') ? c + 2 : c + 1;
} else {
c = str.indexOf(q+']', b);
if (c === -1) c = str.length;
while (str.slice(c - 1, c) === '\\' && b < str.length){
b++;
c = str.indexOf(q+']', b);
}
parts.push(str.slice(i + 2, c).replace(new RegExp('\\'+q,'g'), q));
i = (str.slice(c + 2, c + 3) === '.') ? c + 3 : c + 2;
}
}
}
return parts;
},
// root === true : auto calculate root; must be dot-notation friendly
// root String : the string to use as root
stringify: function(arr, quote){
if(!Array.isArray(arr))
arr = [arr.toString()];
quote = quote === '"' ? '"' : '\'';
return arr.map(function(n){ return '[' + quote + (n.toString()).replace(new RegExp(quote, 'g'), '\\' + quote) + quote + ']'; }).join('');
},
normalize: function(data, quote){
return ObjectPath.stringify(Array.isArray(data) ? data : ObjectPath.parse(data), quote);
},
// Angular
registerModule: function(angular) {
angular.module('ObjectPath', []).provider('ObjectPath', function(){
this.parse = ObjectPath.parse;
this.stringify = ObjectPath.stringify;
this.normalize = ObjectPath.normalize;
this.$get = function(){
return ObjectPath;
};
});
}
};
// AMD
if (typeof define === 'function' && define.amd) {
define(function() {
return {
// this is only namespaced for backwards compatibility when fixing issue #8
ObjectPath: ObjectPath,
// export these as top-level functions
parse: ObjectPath.parse,
stringify: ObjectPath.stringify,
normalize: ObjectPath.normalize
};
});
}
// CommonJS
else if (typeof exports === 'object') {
exports.ObjectPath = ObjectPath;
}
// Browser global
else {
window.ObjectPath = ObjectPath;
}
}();