Skip to content

Fix for #121 to redraw with proper defaults #644

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/schema-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -2677,7 +2677,7 @@ angular.module('schemaForm')
// part of the form or schema is chnaged without it being a new instance.
scope.$on('schemaFormRedraw', function() {
var schema = scope.schema;
var form = scope.initialForm || ['*'];
var form = scope.initialForm ? angular.copy(scope.initialForm) : ['*'];
if (schema) {
render(schema, form);
}
Expand Down
2 changes: 1 addition & 1 deletion dist/schema-form.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/directives/schema-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ angular.module('schemaForm')
// part of the form or schema is chnaged without it being a new instance.
scope.$on('schemaFormRedraw', function() {
var schema = scope.schema;
var form = scope.initialForm || ['*'];
var form = scope.initialForm ? angular.copy(scope.initialForm) : ['*'];
if (schema) {
render(schema, form);
}
Expand Down
53 changes: 53 additions & 0 deletions test/directives/schema-form-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1768,6 +1768,59 @@ describe('directive',function(){
});
});

it('should redraw form with proper defaults on schemaFormRedraw event',function(done) {

inject(function($compile, $rootScope){
var scope = $rootScope.$new();
scope.person = {};

scope.schema = {
type: 'object',
properties: {
name: {type: 'string'}
}
};

scope.form = [{
key: 'name',
type: 'text'
}];

scope.options = {formDefaults: {}};

var tmpl = angular.element('<form sf-schema="schema" sf-form="form" sf-model="person" sf-options="options"></form>');

$compile(tmpl)(scope);
$rootScope.$apply();

expect(tmpl.find('input').attr('disabled')).to.be.undefined;

var disable, enable;
disable = function () {
// form element should be disabled
scope.options.formDefaults.readonly = true;
scope.$broadcast('schemaFormRedraw');
$rootScope.$apply();
expect(tmpl.find('input').attr('disabled')).eq('disabled');

// try to re-enable it by modifying global option
setTimeout(enable, 0);
};

enable = function () {
// form element should be back to enabled
scope.options.formDefaults.readonly = false;
scope.$broadcast('schemaFormRedraw');
$rootScope.$apply();
expect(tmpl.find('input').attr('disabled')).to.be.undefined;

done();
}

setTimeout(disable, 0);
});
});

it('should use supplied template with template field type',function() {

inject(function($compile, $rootScope){
Expand Down