Skip to content

Commit e52a3f2

Browse files
committed
Fix PR #605 error and create test for it
1 parent fa96f5a commit e52a3f2

7 files changed

+168
-27
lines changed

Diff for: dist/angular-schema-form-bootstrap.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* angular-schema-form
33
* @version 1.0.0-alpha.1
4-
* @date Tue, 31 Jan 2017 11:57:55 GMT
4+
* @date Sat, 04 Feb 2017 11:08:45 GMT
55
* @link https://github.com/json-schema-form/angular-schema-form
66
* @license MIT
77
* Copyright (c) 2014-2017 JSON Schema Form

Diff for: dist/angular-schema-form-bootstrap.min.js

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

Diff for: dist/angular-schema-form.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* angular-schema-form
33
* @version 1.0.0-alpha.1
4-
* @date Tue, 31 Jan 2017 13:48:26 GMT
4+
* @date Sat, 04 Feb 2017 11:08:45 GMT
55
* @link https://github.com/json-schema-form/angular-schema-form
66
* @license MIT
77
* Copyright (c) 2014-2017 JSON Schema Form
@@ -2153,10 +2153,11 @@ FIXME: real documentation
21532153
childScope.schemaForm = { form: merged, schema: schema };
21542154

21552155
//clean all but pre existing html.
2156-
Array.prototype.forEach.call(element[0].children, function (child) {
2157-
if ([' ', child.className, ' '].join('').indexOf(' schema-form-ignore ') === -1 && child.querySelectorAll('[sf-insert-field]').length === 0) {
2158-
__WEBPACK_IMPORTED_MODULE_0_angular___default.a.element(child).remove();
2159-
}
2156+
Array.prototype.forEach.call(element.children(), function (child) {
2157+
var jchild = __WEBPACK_IMPORTED_MODULE_0_angular___default.a.element(child);
2158+
if (false === jchild.hasClass('schema-form-ignore')) {
2159+
jchild.remove();
2160+
};
21602161
});
21612162

21622163
// Find all slots.

Diff for: dist/angular-schema-form.min.js

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

Diff for: src/directives/schema-validate.directive.spec.js

+57-13
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@ describe('directive', function() {
88
})
99
);
1010

11+
tv4.defineError('EMAIL', 10001, 'Invalid email address');
12+
tv4.defineKeyword('email', function(data, value, schema) {
13+
if (schema.email) {
14+
if (/^\S+@\S+$/.test(data)) {
15+
return null;
16+
}
17+
return {
18+
code: 10001
19+
};
20+
}
21+
return null;
22+
});
23+
1124
exampleSchema = {
1225
"type": "object",
1326
"title": "Person",
@@ -71,19 +84,6 @@ describe('directive', function() {
7184
);
7285

7386
inject(function($compile,$rootScope) {
74-
tv4.defineError('EMAIL', 10001, 'Invalid email address');
75-
tv4.defineKeyword('email', function(data, value, schema) {
76-
if (schema.email) {
77-
if (/^\S+@\S+$/.test(data)) {
78-
return null;
79-
}
80-
return {
81-
code: 10001
82-
};
83-
}
84-
return null;
85-
});
86-
8787
var scope = $rootScope.$new();
8888
scope.obj = { "email": "NULL" };
8989

@@ -111,4 +111,48 @@ describe('directive', function() {
111111
form.$valid.should.be.false;
112112
});
113113
});
114+
115+
it('should allow custom tv4 error default message to be set', function() {
116+
//TODO test message rename
117+
// app.config(['sfErrorMessageProvider', function(sfErrorMessageProvider) {
118+
// sfErrorMessageProvider.setDefaultMessage(10001, 'Whoa! Can you double check that email address for me?');
119+
// }]);
120+
121+
tmpl = angular.element(
122+
'<div>' +
123+
'<form name="testform" sf-schema="schema" sf-form="form" sf-model="obj"></form>' +
124+
'{{obj}}' +
125+
'</div>'
126+
);
127+
128+
inject(function($compile,$rootScope) {
129+
130+
var scope = $rootScope.$new();
131+
scope.obj = { "email": "NULL" };
132+
133+
scope.schema = exampleSchema;
134+
135+
scope.form = [
136+
{
137+
"key": "email",
138+
"placeholder": "Enter contact email",
139+
"feedback": false
140+
},
141+
{
142+
"type": "submit",
143+
"style": "btn-info",
144+
"title": "OK"
145+
}
146+
];
147+
148+
$compile(tmpl)(scope);
149+
$rootScope.$apply();
150+
151+
var form = tmpl.find('form').eq(0).controller('form');
152+
153+
form.$valid.should.be.true;
154+
tmpl.find('input.btn-info').click();
155+
//TODO form.$valid.should.be.false;
156+
});
157+
});
114158
});

Diff for: src/directives/sf-schema.directive.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,11 @@ sfSelect, sfPath, sfBuilder) {
100100
childScope.schemaForm = { form: merged, schema: schema };
101101

102102
//clean all but pre existing html.
103-
Array.prototype.forEach.call(element[0].children, function(child) {
104-
if (([' ', child.className, ' '].join('')).indexOf(' schema-form-ignore ') === -1 && child.querySelectorAll('[sf-insert-field]').length === 0) {
105-
angular.element(child).remove();
106-
}
103+
Array.prototype.forEach.call(element.children(), function(child) {
104+
let jchild = angular.element(child);
105+
if (false === jchild.hasClass('schema-form-ignore')) {
106+
jchild.remove();
107+
};
107108
});
108109

109110
// Find all slots.

Diff for: src/directives/sf-schema.directive.spec.js

+95
Original file line numberDiff line numberDiff line change
@@ -2882,4 +2882,99 @@ describe('destroy strategy', function() {
28822882
});
28832883
});
28842884

2885+
it('should remove added fields when refreshing or changing content', function (done) {
2886+
var a = {
2887+
schema: {
2888+
"type": "object",
2889+
"title": "Comment",
2890+
"properties": {
2891+
"name": {
2892+
"title": "Name",
2893+
"type": "string"
2894+
},
2895+
"email": {
2896+
"title": "Email",
2897+
"type": "string",
2898+
"pattern": "^\\S+@\\S+$",
2899+
"description": "Email will be used for evil."
2900+
},
2901+
"comment": {
2902+
"title": "Comment",
2903+
"type": "string",
2904+
"maxLength": 20,
2905+
"validationMessage": "Don't be greedy!"
2906+
}
2907+
},
2908+
"required": [
2909+
"name",
2910+
"email",
2911+
"comment"
2912+
]
2913+
},
2914+
form: [
2915+
"name",
2916+
"email",
2917+
{
2918+
"key": "comment",
2919+
"type": "textarea",
2920+
"placeholder": "Make a comment"
2921+
},
2922+
{
2923+
"type": "submit",
2924+
"style": "btn-info",
2925+
"title": "OK"
2926+
}
2927+
]
2928+
};
2929+
2930+
var b = {
2931+
schema: {
2932+
"type": "object",
2933+
"title": "Types",
2934+
"properties": {
2935+
"string": {
2936+
"type": "string",
2937+
"minLength": 3
2938+
},
2939+
"integer": {
2940+
"type": "integer"
2941+
},
2942+
"number": {
2943+
"type": "number"
2944+
},
2945+
"boolean": {
2946+
"type": "boolean"
2947+
}
2948+
},
2949+
"required": [
2950+
"number"
2951+
]
2952+
},
2953+
form: [ "*" ]
2954+
};
2955+
2956+
inject(function ($compile, $rootScope) {
2957+
var scope = $rootScope.$new();
2958+
scope.model = {};
2959+
scope.schema = a.schema;
2960+
scope.form = a.form;
2961+
2962+
var tmpl = angular.element('<form sf-schema="schema" sf-form="form" sf-model="model"></form>');
2963+
2964+
$compile(tmpl)(scope);
2965+
$rootScope.$apply();
2966+
2967+
tmpl.find('.form-group').length.should.be.eq(4);
2968+
2969+
scope.schema = b.schema;
2970+
scope.form = b.form;
2971+
2972+
scope.$broadcast('schemaFormRedraw');
2973+
$rootScope.$apply();
2974+
2975+
tmpl.find('.form-group').length.should.be.eq(3);
2976+
2977+
done();
2978+
});
2979+
});
28852980
});

0 commit comments

Comments
 (0)