Skip to content

Commit e796f0f

Browse files
committed
set validity to the form
1 parent 1c6ebb9 commit e796f0f

File tree

6 files changed

+21
-12
lines changed

6 files changed

+21
-12
lines changed

demo/demo.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@ angular.module('demo')
1515
name: {
1616
type: 'string'
1717
},
18-
age: {
19-
type: 'integer'
18+
location: {
19+
type: 'string',
20+
minLength: 3
2021
}
2122
}
2223
};
2324

2425
$scope.complexModel = {
2526
name: 'Mohsen',
26-
age: 28
27+
location: 'Palo Alto, CA'
2728
};
2829

2930
$scope.$watch('complexModel', function(){

dist/schema-form.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* angular-json-schema-form
33
* https://github.com/mohsen1/angular-json-schema-form
4-
* Version: 0.0.1 - 2015-05-22T20:49:07.357Z
4+
* Version: 0.0.2 - 2015-05-22T21:26:40.666Z
55
* License: MIT
66
*/
77

dist/schema-form.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* angular-json-schema-form
33
* https://github.com/mohsen1/angular-json-schema-form
4-
* Version: 0.0.1 - 2015-05-22T20:49:07.354Z
4+
* Version: 0.0.2 - 2015-05-22T21:26:40.664Z
55
* License: MIT
66
*/
77

@@ -69,13 +69,17 @@ angular.module('mohsen1.schema-form', [])
6969

7070
if (ngModel) {
7171
jsonEditor.setValue(ngModel.$modelValue);
72-
jsonEditor.on('change', setViewValue);
72+
jsonEditor.on('change', setViewValueAndErrors);
7373
}
74+
7475
}
7576

76-
function setViewValue() {
77+
function setViewValueAndErrors() {
7778
scope.$evalAsync(function() {
79+
var errors = jsonEditor.validate();
80+
7881
ngModel.$setViewValue(jsonEditor.getValue());
82+
ngModel.$setValidity('schemaForm', errors.length === 0);
7983
});
8084
}
8185

dist/schema-form.min.css.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!
22
* angular-json-schema-form
33
* https://github.com/mohsen1/angular-json-schema-form
4-
* Version: 0.0.1 - 2015-05-22T20:49:07.357Z
4+
* Version: 0.0.2 - 2015-05-22T21:26:40.666Z
55
* License: MIT
66
*/

dist/schema-form.min.js.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/schema-form.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,17 @@ angular.module('mohsen1.schema-form', [])
6161

6262
if (ngModel) {
6363
jsonEditor.setValue(ngModel.$modelValue);
64-
jsonEditor.on('change', setViewValue);
64+
jsonEditor.on('change', setViewValueAndErrors);
6565
}
66+
6667
}
6768

68-
function setViewValue() {
69+
function setViewValueAndErrors() {
6970
scope.$evalAsync(function() {
71+
var errors = jsonEditor.validate();
72+
7073
ngModel.$setViewValue(jsonEditor.getValue());
74+
ngModel.$setValidity('schemaForm', errors.length === 0);
7175
});
7276
}
7377

0 commit comments

Comments
 (0)