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

Added ability to allow functions supplied to ngfModelInvalid. #2025

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
15 changes: 10 additions & 5 deletions demo/src/main/webapp/js/ng-file-upload-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,11 @@ ngFileUpload.service('Upload', ['$parse', '$timeout', '$compile', '$q', 'UploadE
var invalidModel = upload.attrGetter('ngfModelInvalid', attr);
if (invalidModel) {
$timeout(function () {
$parse(invalidModel).assign(scope, isSingleModel ? invalidFile : invalidFiles);
if (invalidModel.includes('(')){
$parse(invalidModel)(scope, {$invalidFile: invalidFile, $invalidFiles: invalidFiles});
} else {
$parse(invalidModel).assign(scope, isSingleModel ? invalidFile : invalidFiles);
}
});
}
$timeout(function () {
Expand Down Expand Up @@ -1041,8 +1045,8 @@ ngFileUpload.service('Upload', ['$parse', '$timeout', '$compile', '$q', 'UploadE
if (validateAfterResize) {
upload.validate(allNewFiles, keep ? prevValidFiles.length : 0, ngModel, attr, scope)
.then(function (validationResult) {
valids = validationResult.validsFiles;
invalids = validationResult.invalidsFiles;
valids = validationResult.validFiles;
invalids = validationResult.invalidFiles;
updateModel();
});
} else {
Expand Down Expand Up @@ -2096,14 +2100,15 @@ ngFileUpload.service('UploadValidate', ['UploadDataUrl', '$q', '$timeout', funct

el.on('loadedmetadata', success);
el.on('error', error);

var count = 0;

function checkLoadError() {
count++;
$timeout(function () {
if (el[0].parentNode) {
if (el[0].duration) {
success();
} else if (count > 10) {
} else if (count++ > 10) {
error();
} else {
checkLoadError();
Expand Down
4 changes: 2 additions & 2 deletions demo/src/main/webapp/js/ng-file-upload-all.min.js

Large diffs are not rendered by default.

15 changes: 10 additions & 5 deletions demo/src/main/webapp/js/ng-file-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,11 @@ ngFileUpload.service('Upload', ['$parse', '$timeout', '$compile', '$q', 'UploadE
var invalidModel = upload.attrGetter('ngfModelInvalid', attr);
if (invalidModel) {
$timeout(function () {
$parse(invalidModel).assign(scope, isSingleModel ? invalidFile : invalidFiles);
if (invalidModel.includes('(')){
$parse(invalidModel)(scope, {$invalidFile: invalidFile, $invalidFiles: invalidFiles});
} else {
$parse(invalidModel).assign(scope, isSingleModel ? invalidFile : invalidFiles);
}
});
}
$timeout(function () {
Expand Down Expand Up @@ -619,8 +623,8 @@ ngFileUpload.service('Upload', ['$parse', '$timeout', '$compile', '$q', 'UploadE
if (validateAfterResize) {
upload.validate(allNewFiles, keep ? prevValidFiles.length : 0, ngModel, attr, scope)
.then(function (validationResult) {
valids = validationResult.validsFiles;
invalids = validationResult.invalidsFiles;
valids = validationResult.validFiles;
invalids = validationResult.invalidFiles;
updateModel();
});
} else {
Expand Down Expand Up @@ -1674,14 +1678,15 @@ ngFileUpload.service('UploadValidate', ['UploadDataUrl', '$q', '$timeout', funct

el.on('loadedmetadata', success);
el.on('error', error);

var count = 0;

function checkLoadError() {
count++;
$timeout(function () {
if (el[0].parentNode) {
if (el[0].duration) {
success();
} else if (count > 10) {
} else if (count++ > 10) {
error();
} else {
checkLoadError();
Expand Down
4 changes: 2 additions & 2 deletions demo/src/main/webapp/js/ng-file-upload.min.js

Large diffs are not rendered by default.

15 changes: 10 additions & 5 deletions dist/ng-file-upload-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,11 @@ ngFileUpload.service('Upload', ['$parse', '$timeout', '$compile', '$q', 'UploadE
var invalidModel = upload.attrGetter('ngfModelInvalid', attr);
if (invalidModel) {
$timeout(function () {
$parse(invalidModel).assign(scope, isSingleModel ? invalidFile : invalidFiles);
if (invalidModel.includes('(')){
$parse(invalidModel)(scope, {$invalidFile: invalidFile, $invalidFiles: invalidFiles});
} else {
$parse(invalidModel).assign(scope, isSingleModel ? invalidFile : invalidFiles);
}
});
}
$timeout(function () {
Expand Down Expand Up @@ -1041,8 +1045,8 @@ ngFileUpload.service('Upload', ['$parse', '$timeout', '$compile', '$q', 'UploadE
if (validateAfterResize) {
upload.validate(allNewFiles, keep ? prevValidFiles.length : 0, ngModel, attr, scope)
.then(function (validationResult) {
valids = validationResult.validsFiles;
invalids = validationResult.invalidsFiles;
valids = validationResult.validFiles;
invalids = validationResult.invalidFiles;
updateModel();
});
} else {
Expand Down Expand Up @@ -2096,14 +2100,15 @@ ngFileUpload.service('UploadValidate', ['UploadDataUrl', '$q', '$timeout', funct

el.on('loadedmetadata', success);
el.on('error', error);

var count = 0;

function checkLoadError() {
count++;
$timeout(function () {
if (el[0].parentNode) {
if (el[0].duration) {
success();
} else if (count > 10) {
} else if (count++ > 10) {
error();
} else {
checkLoadError();
Expand Down
4 changes: 2 additions & 2 deletions dist/ng-file-upload-all.min.js

Large diffs are not rendered by default.

15 changes: 10 additions & 5 deletions dist/ng-file-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,11 @@ ngFileUpload.service('Upload', ['$parse', '$timeout', '$compile', '$q', 'UploadE
var invalidModel = upload.attrGetter('ngfModelInvalid', attr);
if (invalidModel) {
$timeout(function () {
$parse(invalidModel).assign(scope, isSingleModel ? invalidFile : invalidFiles);
if (invalidModel.includes('(')){
$parse(invalidModel)(scope, {$invalidFile: invalidFile, $invalidFiles: invalidFiles});
} else {
$parse(invalidModel).assign(scope, isSingleModel ? invalidFile : invalidFiles);
}
});
}
$timeout(function () {
Expand Down Expand Up @@ -619,8 +623,8 @@ ngFileUpload.service('Upload', ['$parse', '$timeout', '$compile', '$q', 'UploadE
if (validateAfterResize) {
upload.validate(allNewFiles, keep ? prevValidFiles.length : 0, ngModel, attr, scope)
.then(function (validationResult) {
valids = validationResult.validsFiles;
invalids = validationResult.invalidsFiles;
valids = validationResult.validFiles;
invalids = validationResult.invalidFiles;
updateModel();
});
} else {
Expand Down Expand Up @@ -1674,14 +1678,15 @@ ngFileUpload.service('UploadValidate', ['UploadDataUrl', '$q', '$timeout', funct

el.on('loadedmetadata', success);
el.on('error', error);

var count = 0;

function checkLoadError() {
count++;
$timeout(function () {
if (el[0].parentNode) {
if (el[0].duration) {
success();
} else if (count > 10) {
} else if (count++ > 10) {
error();
} else {
checkLoadError();
Expand Down
4 changes: 2 additions & 2 deletions dist/ng-file-upload.min.js

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion src/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,11 @@ ngFileUpload.service('Upload', ['$parse', '$timeout', '$compile', '$q', 'UploadE
var invalidModel = upload.attrGetter('ngfModelInvalid', attr);
if (invalidModel) {
$timeout(function () {
$parse(invalidModel).assign(scope, isSingleModel ? invalidFile : invalidFiles);
if (invalidModel.includes('(')){
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes it seem like you have to pass the function in like

ngf-model-invalid="method()"

rather than

ngf-model-invalid="method"

Perhaps parse it and use typeof to check instead?

$parse(invalidModel)(scope, {$invalidFile: invalidFile, $invalidFiles: invalidFiles});
} else {
$parse(invalidModel).assign(scope, isSingleModel ? invalidFile : invalidFiles);
}
});
}
$timeout(function () {
Expand Down