Skip to content

Commit e41a027

Browse files
committed
Added onChange callback support. (#4)
Updated example fixed jscs task removed deprecated jscs parameters
1 parent 1e0f5e9 commit e41a027

File tree

9 files changed

+22
-11
lines changed

9 files changed

+22
-11
lines changed

.jscs.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
"requireSpaceAfterKeywords": ["if", "else", "for", "while", "do", "switch", "return", "try", "catch"],
77
"requireSpaceAfterBinaryOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!=="],
88
"requireSpaceBeforeBinaryOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!=="],
9-
"disallowLeftStickedOperators": ["?", "+", "-", "/", "*", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="],
10-
"disallowRightStickedOperators": ["?", "+", "/", "*", ":", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="],
11-
"requireRightStickedOperators": ["!"],
12-
"requireLeftStickedOperators": [","],
139
"disallowSpaceBeforePostfixUnaryOperators": ["++", "--"],
1410
"disallowSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "-", "~", "!"],
1511
"requireOperatorBeforeLineBreak": ["?", "+", "-", "/", "*", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="],

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ The directive exposes an `isValid` property on the scope, which can be used to e
3838
<button type="button" ng-disabled="!isValid">Button 1</button>
3939
```
4040

41+
### Events
42+
The directive allows you to pass a callback function through the `on-change` attribute that will be called whenever a change event is fired on the editor.
43+
```html
44+
<json-editor schema="mySchema" startval="myStartVal" buttons-controller="SyncButtonsController" on-change="onChange()">
45+
```
46+
4147
Building
4248
---------
4349

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-json-editor",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"authors": [
55
"Rodik Hanukaev <[email protected]>",
66
"Topaz Bar <[email protected]>"

demo/app.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ angular.module('demoApp', ['angular-json-editor']).config(function (JsonEditorCo
3030
age: 20
3131
};
3232

33+
$scope.onChange = function () {
34+
console.log('Form changed!');
35+
};
36+
3337
}).controller('AsyncAppController', function ($scope, $http, $timeout) {
3438

3539
// Load with $http

demo/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<h2>Synchronous values</h2>
1414
<div class="container" ng-controller="SyncAppController">
15-
<json-editor schema="mySchema" startval="myStartVal" buttons-controller="SyncButtonsController">
15+
<json-editor schema="mySchema" startval="myStartVal" buttons-controller="SyncButtonsController" on-change="onChange()">
1616

1717
<button type="submit" class="btn btn-success" ng-click="onSubmit($event)" ng-disabled="!isValid">
1818
<span class="glyphicon glyphicon-check"></span>

dist/angular-json-editor.min.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.

grunt/codestyle.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ module.exports = function (grunt) {
1717
});
1818

1919
grunt.loadNpmTasks('grunt-contrib-jshint');
20-
grunt.loadNpmTasks('grunt-jscs-checker');
20+
grunt.loadNpmTasks('grunt-jscs');
2121
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-json-editor",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"repository": {
55
"type": "git",
66
"url": "git://github.com/rodikh/angular-json-editor.git"

src/angular-json-editor.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ angular.module('angular-json-editor', []).constant('JsonEditorConfig', {
1212
scope: {
1313
schema: '=',
1414
startval: '=',
15-
buttonsController: '@'
15+
buttonsController: '@',
16+
onChange: '&'
1617
},
1718
controller: ['$scope', '$attrs', '$controller', function ($scope, $attrs, $controller) {
1819

@@ -81,6 +82,10 @@ angular.module('angular-json-editor', []).constant('JsonEditorConfig', {
8182
});
8283

8384
editor.on('change', function () {
85+
// Fire the onChange callback
86+
if (typeof scope.onChange === 'function') {
87+
scope.onChange();
88+
}
8489
scope.$apply(function () {
8590
scope.isValid = (editor.validate().length === 0);
8691
});

0 commit comments

Comments
 (0)