Skip to content

Commit

Permalink
Fix for checkboxes when model is undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlgj committed Sep 24, 2015
1 parent b37f208 commit d503bfe
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
22 changes: 14 additions & 8 deletions dist/schema-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -2293,6 +2293,18 @@ function(sel, sfPath, schemaForm) {
}
};

// If model is undefined make sure it gets set.
var getOrCreateModel = function() {
var model = scope.modelArray;
if (!model) {
var selection = sfPath.parse(attrs.sfNewArray);
model = [];
sel(selection, scope, model);
scope.modelArray = model;
}
return model;
};

// We need the form definition to make a decision on how we should listen.
var once = scope.$watch('form', function(form) {
if (!form) {
Expand Down Expand Up @@ -2363,7 +2375,7 @@ function(sel, sfPath, schemaForm) {
//To get two way binding we also watch our titleMapValues
scope.$watchCollection('titleMapValues', function(vals, old) {
if (vals && vals !== old) {
var arr = scope.modelArray;
var arr = getOrCreateModel();

// Apparently the fastest way to clear an array, readable too.
// http://jsperf.com/array-destroy/32
Expand Down Expand Up @@ -2392,13 +2404,7 @@ function(sel, sfPath, schemaForm) {
var empty;

// Create and set an array if needed.
var model = scope.modelArray;
if (!model) {
var selection = sfPath.parse(attrs.sfNewArray);
model = [];
sel(selection, scope, model);
scope.modelArray = model;
}
var model = getOrCreateModel();

// Same old add empty things to the array hack :(
if (scope.form && scope.form.schema && scope.form.schema.items) {
Expand Down
Loading

0 comments on commit d503bfe

Please sign in to comment.