Skip to content
Merged
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 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