Skip to content
This repository was archived by the owner on Feb 9, 2024. It is now read-only.
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
30 changes: 23 additions & 7 deletions dist/angular-chips.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
return obj && angular.isFunction(obj.then);
}

function isArray(obj) {
return Object.prototype.toString.call(obj) === '[object Array]';
}

/*
* update values to ngModel reference
*/
Expand Down Expand Up @@ -84,6 +88,7 @@
var model = ngModel(ngModelCtrl);
var isDeferFlow = iAttrs.hasOwnProperty('defer');
var functionParam = getParamKey(iAttrs.render);
var isUnique = iAttrs.hasOwnProperty('unique'); // TODO check uniqueness

/*
* @scope.chips.addChip should be called by chipControl directive or custom XXXcontrol directive developed by end user
Expand All @@ -106,22 +111,33 @@
} else { updatedData = data }

if (!updatedData) {
return false;
return false;
}

if (isPromiseLike(updatedData)) {
updatedData.then(function(response) {
model.add(response);
});
scope.chips.list.push(new DeferChip(data, updatedData));
scope.chips.list.push(
new DeferChip(
data,
updatedData.then(function(response) {
response = isArray(response) ? response : [response];
var first = response.shift() // get first element, it will be populated to DeferChip
update(response.map(function(r) { return { defer: r } })); // add all other elements, if any
model.add(first);
return first;
})
)
);
scope.$apply();
} else {
update(updatedData);
}

function update(data) {
scope.chips.list.push(data);
model.add(data);
data = isArray(data) ? data : [data];
for (var i = 0; i < data.length; i++) {
scope.chips.list.push(data[i]);
model.add(data[i]);
}
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion dist/angular-chips.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 23 additions & 7 deletions src/js/directives/chips.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
return obj && angular.isFunction(obj.then);
}

function isArray(obj) {
return Object.prototype.toString.call(obj) === '[object Array]';
}

/*
* update values to ngModel reference
*/
Expand Down Expand Up @@ -81,6 +85,7 @@
var model = ngModel(ngModelCtrl);
var isDeferFlow = iAttrs.hasOwnProperty('defer');
var functionParam = getParamKey(iAttrs.render);
var isUnique = iAttrs.hasOwnProperty('unique'); // TODO check uniqueness

/*
* @scope.chips.addChip should be called by chipControl directive or custom XXXcontrol directive developed by end user
Expand All @@ -103,22 +108,33 @@
} else { updatedData = data }

if (!updatedData) {
return false;
return false;
}

if (isPromiseLike(updatedData)) {
updatedData.then(function(response) {
model.add(response);
});
scope.chips.list.push(new DeferChip(data, updatedData));
scope.chips.list.push(
new DeferChip(
data,
updatedData.then(function(response) {
response = isArray(response) ? response : [response];
var first = response.shift() // get first element, it will be populated to DeferChip
update(response.map(function(r) { return { defer: r } })); // add all other elements, if any
model.add(first);
return first;
})
)
);
scope.$apply();
} else {
update(updatedData);
}

function update(data) {
scope.chips.list.push(data);
model.add(data);
data = isArray(data) ? data : [data];
for (var i = 0; i < data.length; i++) {
scope.chips.list.push(data[i]);
model.add(data[i]);
}
}

return true;
Expand Down
Loading