Skip to content

Commit 4994734

Browse files
committed
Merge branch 'release/0.7.8'
2 parents e72b977 + 9e14725 commit 4994734

31 files changed

+246
-95
lines changed

.npmignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/.*

CHANGELOG

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
v0.7.8
2+
------
3+
* Thanks to @burdiuz for finding a memory leak issue and finding a solution. And thanks to @davidlgj for implementing that solution.
4+
* Post render event, thanks @mrijken
5+
* Events documentation, thanks @Dervisevic
6+
* startEmpty documentation, thanks @davidlj
7+
* npm and bower updates, thanks @Dervisevic
8+
* x-schema-form attribute, thanks @davidlgj
9+
* htmlClass and fieldHtmlClass form options, thanks @davidlgj
10+
111
v0.7.7
212
------
313
* Array ref changes in model updates form, thanks @Sandreu

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,13 @@ angular.module('myModule', ['schemaForm']);
145145

146146
Add-ons
147147
------
148-
There is currently three add-ons, a date picker, a colorpicker and the wysiwyg html editor tinymce.
148+
There are a couple of add-ons, a date picker, a colorpicker and two wysiwyg editors.
149149
They have their own repos and you can find them here with usage instructions:
150150

151151
* [https://github.com/Textalk/angular-schema-form-datepicker](https://github.com/Textalk/angular-schema-form-datepicker)
152152
* [https://github.com/Textalk/angular-schema-form-colorpicker](https://github.com/Textalk/angular-schema-form-colorpicker)
153153
* [https://github.com/Textalk/angular-schema-form-tinymce](https://github.com/Textalk/angular-schema-form-tinymce)
154+
* [https://github.com/webcanvas/angular-schema-form-ckeditor](https://github.com/webcanvas/angular-schema-form-ckeditor)
154155

155156
Your can also [create your own add-ons!](docs/extending.md)
156157

bower.json

+13-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
"dist/schema-form.min.js",
55
"dist/bootstrap-decorator.min.js"
66
],
7-
"version": "0.7.7",
7+
"version": "0.7.8",
88
"authors": [
99
"Textalk",
10-
"David Jensen <[email protected]>"
10+
"David Jensen <[email protected]>",
11+
"Cameron Edwards",
12+
"Mike Marcacci",
13+
"Denis Dervisevic <[email protected]>"
1114
],
1215
"moduleType": [
1316
"globals"
@@ -23,10 +26,17 @@
2326
"license": "MIT",
2427
"ignore": [
2528
"**/.*",
29+
"*.js",
30+
"*.json",
2631
"node_modules",
2732
"bower_components",
2833
"test",
29-
"coverage"
34+
"coverage",
35+
"docs",
36+
"examples",
37+
"gulp",
38+
"CHANGELOG",
39+
"LICENSE"
3040
],
3141
"dependencies": {
3242
"angular": ">= 1.2",

dist/bootstrap-decorator.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/schema-form.js

+24-5
Original file line numberDiff line numberDiff line change
@@ -481,8 +481,15 @@ angular.module('schemaForm').provider('schemaForm',
481481
var def;
482482
for (var i = 0; i < rules.length; i++) {
483483
def = rules[i](name, schema, options);
484+
484485
//first handler in list that actually returns something is our handler!
485486
if (def) {
487+
488+
// Do we have form defaults in the schema under the x-schema-form-attribute?
489+
if (def.schema['x-schema-form'] && angular.isObject(def.schema['x-schema-form'])) {
490+
def = angular.extend(def, def.schema['x-schema-form']);
491+
}
492+
486493
return def;
487494
}
488495
}
@@ -508,14 +515,16 @@ angular.module('schemaForm').provider('schemaForm',
508515
if (schema.minimum) { f.minimum = schema.minimum + (schema.exclusiveMinimum ? 1 : 0); }
509516
if (schema.maximum) { f.maximum = schema.maximum - (schema.exclusiveMaximum ? 1 : 0); }
510517

511-
//Non standard attributes
518+
// Non standard attributes (DONT USE DEPRECATED)
519+
// If you must set stuff like this in the schema use the x-schema-form attribute
512520
if (schema.validationMessage) { f.validationMessage = schema.validationMessage; }
513521
if (schema.enumNames) { f.titleMap = canonicalTitleMap(schema.enumNames, schema['enum']); }
514522
f.schema = schema;
515523

516524
// Ng model options doesn't play nice with undefined, might be defined
517525
// globally though
518526
f.ngModelOptions = f.ngModelOptions || {};
527+
519528
return f;
520529
};
521530

@@ -1279,7 +1288,7 @@ angular.module('schemaForm')
12791288
//Since we are dependant on up to three
12801289
//attributes we'll do a common watch
12811290
var lastDigest = {};
1282-
1291+
var childScope;
12831292
scope.$watch(function() {
12841293

12851294
var schema = scope.schema;
@@ -1295,8 +1304,17 @@ angular.module('schemaForm')
12951304
var merged = schemaForm.merge(schema, form, ignore, scope.options);
12961305
var frag = document.createDocumentFragment();
12971306

1307+
// Create a new form and destroy the old one.
1308+
// Not doing keeps old form elements hanging around after
1309+
// they have been removed from the DOM
1310+
// https://github.com/Textalk/angular-schema-form/issues/200
1311+
if (childScope) {
1312+
childScope.$destroy();
1313+
}
1314+
childScope = scope.$new();
1315+
12981316
//make the form available to decorators
1299-
scope.schemaForm = {form: merged, schema: schema};
1317+
childScope.schemaForm = {form: merged, schema: schema};
13001318

13011319
//clean all but pre existing html.
13021320
element.children(':not(.schema-form-ignore)').remove();
@@ -1335,7 +1353,7 @@ angular.module('schemaForm')
13351353
element[0].appendChild(frag);
13361354

13371355
//compile only children
1338-
$compile(element.children())(scope);
1356+
$compile(element.children())(childScope);
13391357

13401358
//ok, now that that is done let's set any defaults
13411359
schemaForm.traverseSchema(schema, function(prop, path) {
@@ -1346,7 +1364,8 @@ angular.module('schemaForm')
13461364
}
13471365
}
13481366
});
1349-
}
1367+
};
1368+
scope.$emit('sf-render-finished', element);
13501369
});
13511370
}
13521371
};

dist/schema-form.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/index.md

+40-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Documentation
44
1. [Basic Usage](#basic-usage)
55
1. [Handling Submit](#handling-submit)
66
1. [Global Options](#global-options)
7+
1. [Form defaults in schema](#form-defaults-in-schema)
78
1. [Form types](#form-types)
89
1. [Default form types](#default-form-types)
910
1. [Form definitions](#form-definitions)
@@ -25,6 +26,7 @@ Documentation
2526
1. [array](#array)
2627
1. [tabarray](#tabarray)
2728
1. [Post process function](#post-process-function)
29+
1. [Events](#events)
2830
1. [Manual field insertion](#manual-field-insertion)
2931
1. [Extending Schema Form](extending.md)
3032

@@ -173,7 +175,29 @@ Ex.
173175
</div>
174176
```
175177
178+
Form defaults in schema
179+
-----------------------
180+
Its recommended to split presentation and validation into a form definition and a json schema. But
181+
if you for some reason can't do this, but *do* have the power to change the schema, you can supply form
182+
default values within the schema using the custom attribute `x-schema-form`. `x-schema-form` should
183+
be a form object and acts as form definition defaults for that field.
176184
185+
Example schema.
186+
```js
187+
{
188+
"type": "object",
189+
"properties": {
190+
"comment": {
191+
"type": "string",
192+
"title": "Comment",
193+
"x-schema-form": {
194+
"type": "textarea",
195+
"placeholder": "Don't hold back"
196+
}
197+
}
198+
}
199+
}
200+
```
177201
178202
Form types
179203
----------
@@ -314,8 +338,10 @@ General options most field types can handle:
314338
feedback: false, // Inline feedback icons
315339
placeholder: "Input...", // placeholder on inputs and textarea
316340
ngModelOptions: { ... }, // Passed along to ng-model-options
317-
readonly: true // Same effect as readOnly in schema. Put on a fieldset or array
341+
readonly: true, // Same effect as readOnly in schema. Put on a fieldset or array
318342
// and their items will inherit it.
343+
htmlClass: "street foobar", // CSS Class(es) to be added to the container div
344+
fieldHtmlClass: "street" // CSS Class(es) to be added to field input (or similar)
319345
}
320346
```
321347
@@ -836,6 +862,9 @@ need the reordering.
836862
In the form definition you can refer to properties of an array item by the empty
837863
bracket notation. In the `key` simply end the name of the array with `[]`
838864
865+
By default the array will start with one *undefined* value so that the user is presented with one a
866+
form, to supress this the attribute `startEmpty` to `true`
867+
839868
Given the schema:
840869
```json
841870
{
@@ -888,7 +917,7 @@ function FormCtrl($scope) {
888917
889918
Example with sub form, note that you can get rid of the form field the object wrapping the
890919
subform fields gives you per default by using the `items` option in the
891-
form definition.
920+
form definition, also example of `startEmpty`.
892921
893922
```javascript
894923
function FormCtrl($scope) {
@@ -926,7 +955,8 @@ function FormCtrl($scope) {
926955
"subforms[].nick",
927956
"subforms[].name",
928957
"subforms[].emails",
929-
]
958+
],
959+
startEmpty: true
930960
}
931961
];
932962
}
@@ -1029,7 +1059,14 @@ angular.module('myModule', ['schemaForm']).config(function(schemaFormProvider){
10291059
});
10301060
```
10311061
1062+
Events
1063+
---------------------
1064+
Events are emitted or broadcast at various points in the process of rendering or validating the
1065+
form. Below is a list of these events and how they are propagated.
10321066
1067+
| Event | When | Type | Arguments |
1068+
|:--------------------:|:----------------------:|:-----:|:----------------------------------:|
1069+
| `sf-render-finished` | After form is rendered | emit | The sf-schema directives's element |
10331070
10341071
### Manual field insertion
10351072
There is a limited feature for controlling manually where a generated field should go so you can

package.json

+30-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,34 @@
11
{
22
"name": "angular-schema-form",
3-
"version": "0.7.7",
4-
"description": "Create forms from a JSON schema",
3+
"version": "0.7.8",
4+
"description": "Create complex forms from a JSON schema with angular.",
5+
"repository": "Textalk/angular-schema-form",
6+
"main": "dist/schema-form.min.js",
57
"scripts": {
68
"test": "rm -fr coverage && ./node_modules/karma/bin/karma start --single-run --browsers PhantomJS karma.conf.js && find coverage/ -name lcov.info -print0 | xargs -0 cat | ./node_modules/coveralls/bin/coveralls.js"
79
},
810
"author": "Textalk",
11+
"contributors": [
12+
"David Jensen <[email protected]> (https://github.com/davidlgj)",
13+
"Cameron Edwards (https://github.com/cameronprattedwards)",
14+
"Mike Marcacci (https://github.com/mike-marcacci)",
15+
"Denis Dervisevic <[email protected]> (https://github.com/Dervisevic)"
16+
],
917
"license": "MIT",
18+
"dependencies": {
19+
"angular": ">= 1.2",
20+
"tv4": "~1.0.15",
21+
"angular-sanitize": ">= 1.2",
22+
"objectpath": "~1.1.0"
23+
},
24+
"keywords": [
25+
"angular",
26+
"angularjs",
27+
"form",
28+
"json",
29+
"json-schema",
30+
"schema"
31+
],
1032
"devDependencies": {
1133
"chai": "^1.9.0",
1234
"coveralls": "^2.11.0",
@@ -28,5 +50,11 @@
2850
"sinon": "^1.9.0",
2951
"sinon-chai": "^2.5.0",
3052
"streamqueue": "0.0.5"
53+
},
54+
"licenses": [
55+
{
56+
"type": "MIT",
57+
"url": "https://raw.githubusercontent.com/Textalk/angular-schema-form/master/LICENSE"
3158
}
59+
]
3260
}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<div class="btn-group" ng-transclude></div>
1+
<div class="btn-group schema-form-actions {{form.htmlClass}}" ng-transclude></div>

src/directives/decorators/bootstrap/actions.html

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
<div class="btn-group">
1+
<div class="btn-group schema-form-actions {{form.htmlClass}}">
22
<input ng-repeat-start="item in form.items"
33
type="submit"
4-
class="btn {{ item.style || 'btn-primary' }}"
4+
class="btn {{ item.style || 'btn-default' }} {{form.fieldHtmlClass}}"
55
value="{{item.title}}"
66
ng-if="item.type === 'submit'">
7-
<button ng-repeat-end class="btn {{ item.style || 'btn-default' }}"
7+
<button ng-repeat-end
8+
class="btn {{ item.style || 'btn-default' }} {{form.fieldHtmlClass}}"
89
type="button"
910
ng-disabled="form.readonly"
1011
ng-if="item.type !== 'submit'"

src/directives/decorators/bootstrap/array.html

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
<div sf-array="form" ng-model="$$value$$" ng-model-options="form.ngModelOptions">
1+
<div sf-array="form" class="schema-form-array {{form.htmlClass}}"
2+
ng-model="$$value$$" ng-model-options="form.ngModelOptions">
23
<h3 ng-show="form.title && form.notitle !== true">{{ form.title }}</h3>
34
<ol class="list-group" ng-model="modelArray" ui-sortable>
4-
<li class="list-group-item" ng-repeat="item in modelArray track by $index">
5+
<li class="list-group-item {{form.fieldHtmlClass}}"
6+
ng-repeat="item in modelArray track by $index">
57
<button ng-hide="form.readonly"
68
ng-click="deleteFromArray($index)"
79
style="position: relative; z-index: 20;"
@@ -12,7 +14,7 @@ <h3 ng-show="form.title && form.notitle !== true">{{ form.title }}</h3>
1214
</li>
1315
</ol>
1416
<div class="clearfix" style="padding: 15px;">
15-
<button ng-hide="form.readonly"
17+
<button ng-hide="form.readonly || form.add === null"
1618
ng-click="appendToArray()"
1719
type="button"
1820
class="btn {{ form.style.add || 'btn-default' }} pull-right">

src/directives/decorators/bootstrap/checkbox.html

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
<div class="checkbox" ng-class="{'has-error': hasError(), 'has-success': hasSuccess()}">
1+
<div class="checkbox schema-form-checkbox {{form.htmlClass}}"
2+
ng-class="{'has-error': hasError(), 'has-success': hasSuccess()}">
23
<label>
34
<input type="checkbox"
45
sf-changed="form"
56
ng-disabled="form.readonly"
67
ng-model="$$value$$"
78
ng-model-options="form.ngModelOptions"
8-
schema-validate="form">
9+
schema-validate="form"
10+
class="{{form.fieldHtmlClass}}"
11+
name="{{form.key.slice(-1)[0]}}">
912
<span ng-bind-html="form.title"></span>
1013
</label>
1114

src/directives/decorators/bootstrap/checkboxes.html

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
<div sf-array="form" ng-model="$$value$$" class="form-group" ng-class="{'has-error': hasError(), 'has-success': hasSuccess()}">
1+
<div sf-array="form" ng-model="$$value$$"
2+
class="form-group schema-form-checkboxes {{form.htmlClass}}"
3+
ng-class="{'has-error': hasError(), 'has-success': hasSuccess()}">
24
<label class="control-label" ng-show="showTitle()">{{form.title}}</label>
35
<div class="checkbox" ng-repeat="val in titleMapValues track by $index" >
46
<label>
57
<input type="checkbox"
68
ng-disabled="form.readonly"
79
sf-changed="form"
8-
ng-model="titleMapValues[$index]">
10+
class="{{form.fieldHtmlClass}}"
11+
ng-model="titleMapValues[$index]"
12+
name="{{form.key.slice(-1)[0]}}">
913
<span ng-bind-html="form.titleMap[$index].name"></span>
1014
</label>
1115

src/directives/decorators/bootstrap/default.html

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
<div class="form-group" ng-class="{'has-error': hasError(), 'has-success': hasSuccess(), 'has-feedback': form.feedback !== false }">
1+
<div class="form-group schema-form-{{form.type}} {{form.htmlClass}}"
2+
ng-class="{'has-error': hasError(), 'has-success': hasSuccess(), 'has-feedback': form.feedback !== false }">
23
<label class="control-label" ng-show="showTitle()">{{form.title}}</label>
34

45
<input ng-show="form.key"
56
type="{{form.type}}"
67
step="any"
78
sf-changed="form"
89
placeholder="{{form.placeholder}}"
9-
class="form-control"
10+
class="form-control {{form.fieldHtmlClass}}"
1011
ng-model-options="form.ngModelOptions"
1112
ng-model="$$value$$"
1213
ng-disabled="form.readonly"
13-
schema-validate="form">
14+
schema-validate="form"
15+
name="{{form.key.slice(-1)[0]}}">
1416
<span ng-if="form.feedback !== false"
1517
class="form-control-feedback"
1618
ng-class="evalInScope(form.feedback) || {'glyphicon': true, 'glyphicon-ok': hasSuccess(), 'glyphicon-remove': hasError() }"></span>

0 commit comments

Comments
 (0)