Skip to content

Commit

Permalink
Merge pull request #134 from vkovrizhkin/master
Browse files Browse the repository at this point in the history
new method for getting index for new items. Fix duplicate index after…
  • Loading branch information
Eugene Terentev authored Oct 21, 2018
2 parents 5d96cc3 + bed0554 commit d9ef016
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/widget/assets/js/upload-kit.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
},
createItem: function(file){
var name = options.name;
var index = methods.getNumberOfFiles();
var index = methods.getNewItemIndex();
if (options.multiple) {
name += '[' + index + ']';
}
Expand Down Expand Up @@ -195,6 +195,13 @@
getNumberOfFiles: function() {
return $container.find('.files .upload-kit-item').length;
},
getNewItemIndex: function () {
var existingIndexes = []
$container.find('.files .upload-kit-item').each(function () {
existingIndexes.push($(this).val());
})
return existingIndexes.length ? (Math.max(...existingIndexes)+1) : 0;
},
updateOrder: function () {
$files.find('.upload-kit-item').each(function(index, item){
$(item).find('input[data-role=order]').val(index);
Expand Down

0 comments on commit d9ef016

Please sign in to comment.