Skip to content

Commit 4c7edf2

Browse files
committed
Fixed examples to work with arrays
1 parent eba144a commit 4c7edf2

File tree

8 files changed

+39
-43
lines changed

8 files changed

+39
-43
lines changed

README.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,26 @@ Angular Schema Form
88
[![Code Coverage](https://img.shields.io/coveralls/json-schema-form/angular-schema-form.svg?style=flat-square)](https://coveralls.io/github/json-schema-form/angular-schema-form?branch=development)
99

1010

11-
1211
Generate forms from JSON schemas using AngularJS!
1312

14-
Branch Status
15-
-------------
13+
Branch Status & New Add-On
14+
--------------------------
1615
This branch will be the **next version of Angular Schema Form**, currently please use
1716
the **examples/example.html** file as the best example to get the framework working.
1817

19-
The example uses **schema-form.js** and **angular-schema-form-bootstrap.js** for the
18+
The example uses **schema-form.js** and **angular-schema-form-bootstrap.js** for the
2019
version of the code it executes, if you want your page to behave the same you
2120
obviously need the same version!
2221

23-
The new webpack compilation has made it easier to manage files and code and run build
24-
scripts, but it is still not easy enough for users unfamiliar with it yet.
22+
The new Webpack compilation has made it easier to manage files and code and run build
23+
scripts, but it is still not easy enough for users unfamiliar with it... yet.
24+
25+
### Add-on
26+
To see how to make an **add-on** work I have now included the **calculate** add-on file within the **examples/add-on** directory.
27+
28+
## Yet to be migrated
29+
Currently **copyValueTo** and some **array** related features are not working as expected and remain the highest priority to ensure backwards compatibility is maintained where possible.
30+
2531

2632
The Blog / The Web Site / The Twitter / The Movie
2733
------------------------------------------------

dist/schema-form.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3431,7 +3431,7 @@ return /******/ (function(modules) { // webpackBootstrap
34313431
exports.default = function (schemaForm, sfPath) {
34323432
return {
34333433
scope: true,
3434-
require: ['^^sfNewArray'],
3434+
require: ['?^^sfNewArray'],
34353435
controller: ['$scope', function SFKeyController($scope) {
34363436
this.key = $scope.form && $scope.form.key ? $scope.form.key.splice(0, -2) : [];
34373437
}],

dist/schema-form.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/add-on/calculate.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
* I calculate a field value based on a provided mathematical string
33
*
44
* @homepage https://github.com/Anthropic/angular-schema-form-calculate
5+
*
6+
* NOTE: This version is not in sync with the source repo as it has
7+
* been modified to work with the new version of the framework in development
8+
*
59
* @example
610
* {
711
* "type":"calculate",
@@ -24,22 +28,18 @@ angular
2428
link: {
2529
post: function(scope, element, attrs, ctrl) {
2630
var watchKeys = scope.form.watch,
27-
key,
31+
key, keyFixed, exec,
2832
i;
2933

3034
scope.form.format = scope.form.format || 'number';
3135

3236
for (i=0; i < watchKeys.length; i++) {
33-
key = watchKeys[i];
37+
key = watchKeys[i].split('[]');
38+
keyFixed = key.reduce(function(pv, cv, ci, ta){
39+
return '' + pv + ((cv[0]=='.')? '['+scope.$i[ci-1]+']'+cv: cv);
40+
});
3441

35-
scope.$watch(function() {
36-
return $interpolate('{{' + key + '}}', false, null, true)({
37-
model: scope.model,
38-
$i: scope.$i,
39-
$index: scope.$index,
40-
path: scope.path
41-
});
42-
},
42+
scope.$watch(keyFixed,
4343
function (val, old) {
4444
var newValue = $interpolate('{{' + scope.form.calculate + '}}', false, null, true)({
4545
model: scope.model,

examples/data/calculate.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,14 @@
5151
{
5252
"key": "area",
5353
"type": "calculate",
54-
"watch": [ "property[0].width", "property[0].length" ],
55-
"calculate": "model.property[0].width * model.property[0].length"
54+
"watch": [ "model.width", "model.length" ],
55+
"calculate": "model.width * model.length"
5656
},
5757
"width",
5858
"length",
5959
"area",
6060
{
61+
"title": "{{ value.name || 'Tab ' + $index }}",
6162
"key": "property",
6263
"type": "tabarray",
6364
"add": "New",
@@ -68,7 +69,13 @@
6869
"property[].name",
6970
"property[].width",
7071
"property[].length",
71-
"property[].area"
72+
"property[].area",
73+
{
74+
"key": "property[].area",
75+
"type": "calculate",
76+
"watch": [ "model.property[].width", "model.property[].length" ],
77+
"calculate": "model.property[$i[0]].width * model.property[$i[0]].length"
78+
}
7279
]
7380
},
7481
{

examples/data/titlemaps.json

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,6 @@
1717
"enum": ["a","b","c"]
1818
},
1919
"noenum": { "type": "string", "title": "No enum, but forms says it's a select", "default": "a3" },
20-
"selectOptionData": {
21-
"type": "string",
22-
"title": "Dynamic Options",
23-
"default": "The Terminator"
24-
},
25-
"radios": {
26-
"title": "Basic radio button example to pick remote dataset for below select 'Remote Options'",
27-
"type": "string",
28-
"enum": ["books","movies"]
29-
},
30-
"selectOptionRemote": {
31-
"type": "string",
32-
"title": "Remote Options",
33-
"links":[
34-
{ "rel": "options", "href": "./data/remote-titlemap-{radios}.json" }
35-
]
36-
},
3720
"array": {
3821
"title": "Array with enum defaults to 'checkboxes'",
3922
"type": "array",

examples/example.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ <h1>Schema Form Example</h1>
142142
<div class="col-sm-4">
143143
<h3>The Generated Form</h3>
144144

145-
<form name="ngform" sf-model="modelData" sf-form="form" sf-schema="schema" ng-submit="submitForm(ngform,modelData)" sf-options="{ formDefaults: { ngModelOptions: { updateOn: 'blur' } }}"></form>
145+
<form name="ngform" sf-model="modelData" sf-form="form" sf-schema="schema" ng-submit="submitForm(ngform,modelData)" sf-options="{ formDefaults: { ngModelOptions: { timezone: '+0430' } }}"></form>
146146
<!--
147147
<form name="ngform"
148148
sf-model="modelData"
@@ -236,17 +236,17 @@ <h3>Schema</h3>
236236
app.controller('TestCtrl', function($scope, $http, $location) {
237237

238238
$scope.tests = [
239-
{ name: "Array Radio-Buttons", data: 'data/array-radiobuttons.json' },
240-
{ name: "Calculate", data: 'data/calculate.json' },
241-
{ name: "Deep Array", data: 'data/deep-array.json' },
242239
{ name: "Simple", data: 'data/simple.json' },
243240
{ name: "Basic JSON Schema Type", data: 'data/types.json' },
244241
{ name: "Bootstrap Grid", data: 'data/grid.json' },
245242
{ name: "Complex Key Support", data: 'data/complex-keys.json' },
246243
{ name: "Array", data: 'data/array.json' },
247244
{ name: "Tab Array", data: 'data/tabarray.json' },
245+
{ name: "Deep Array", data: 'data/deep-array.json' },
246+
//{ name: "Array Radio-Buttons", data: 'data/array-radiobuttons.json' },
248247
{ name: "TitleMap Examples", data: 'data/titlemaps.json' },
249248
{ name: "Kitchen Sink", data: 'data/sink.json' },
249+
{ name: "Calculate", data: 'data/calculate.json' },
250250
{ name: "Hack: Conditional required", data: 'data/conditional-required.json' }
251251
];
252252

src/directives/keyController.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
export default function(schemaForm, sfPath) {
55
return {
66
scope: true,
7-
require: ['^^sfNewArray'],
7+
require: ['?^^sfNewArray'],
88
controller: ['$scope', function SFKeyController($scope) {
99
this.key = ($scope.form && $scope.form.key) ? $scope.form.key.splice(0, -2) : [];
1010
}],

0 commit comments

Comments
 (0)