- Home
- Forum
- Angular - EJ 2
- Validation message for the image dimensions selected in ejs uploader
Validation message for the image dimensions selected in ejs uploader
In ejs-uploader after selecting the image need to show the validation message if the image dimensions exceeds the specified dimensions and upload button should be disabled.
In the above screenshot validation for image size is taking place , In the same scenario for the image dimensions as well we need to restrict it by showing a validation message and restricting to upload.
can you please show the to achieve it.
|
public onSelect(args) {
var reader = new FileReader();
reader.readAsDataURL(args.filesData[0].rawFile);
reader.onload = function(e) {
var image = new Image();
image.src = e.target.result;
image.onload = () => {
var height = this.height;
var width = this.width;
console.log(this);
if (
(height >= 1024 || height <= 1100) &&
(width >= 750 || width <= 800)
) {
alert('Height and Width must not exceed 1100*800.');
var upload = document.getElementById('defaultfileupload');
upload.ej2_instances[0].l10n.currentLocale.uploadSuccessMessage =
'File size exceed';
return false;
}
alert('Uploaded image has valid Height and Width.');
return true;
};
};
} |
Hi Berly,
Thank you for responding I have tried this sample but I was getting the below error,
can you please show a solution for this issue.
- error TS2531: Object is possibly 'null'
|
upload!.ej2_instances[0].l10n.currentLocale.uploadSuccessMessage ='File size exceed'; |
reference link: https://stackoverflow.com/questions/40349987/how-to-suppress-error-ts2533-object-is-possibly-null-or-undefined
- error TS2339: property ej2_instances does not exist on type HTMLEelement
Since ‘ej2_instances’ is a private property and cannot be accessed via explicit type declaration. We suggest you use it as any type.
|
(upload as any).ej2_instances[0].l10n.currentLocale.uploadSuccessMessage ='File size exceed'; |
reference link: https://stackoverflow.com/questions/38324949/error-ts2339-property-x-does-not-exist-on-type-y
Hi Prince,
Thank you for responding, I have tried the code snippet, it is working like this
The message is displaying after clicking on upload.
I need the message before uploading the image and it should be in red color as a failure scenario and upload needs to be restricted. Can you please find a solution for this.
Thanks,
Lahari Navudu
Hi Berly,
The message is displaying after clicking on upload.
I need the message before uploading the image and it should be in red color as a failure scenario and upload needs to be restricted. Can you please find a solution for this.
Thank you
Lahari Navudu
|
public onSelect(args) {
var reader = new FileReader();
reader.readAsDataURL(args.filesData[0].rawFile);
reader.onload = function(e) {
var image = new Image();
(image as any).src = e.target.result;
image.onload = function() {
var height = this.height;
var width = this.width;
console.log(this);
if (
(height >= 1024 || height <= 1100) &&
(width >= 750 || width <= 800)
) {
alert('Height and Width must not exceed 1100*800.');
var upload = document.getElementById('defaultfileupload');
document.querySelector('.e-file-status').innerHTML =
'File size exceed';
document.querySelector('.e-file-status').style.color = 'red';
document
.querySelector('.e-file-upload-btn')
.classList.add('e-disabled');
return false;
}
alert('Uploaded image has valid Height and Width.');
document.querySelector('.e-file-status').style.color = 'green';
document
.querySelector('.e-file-upload-btn')
.classList.remove('e-disabled');
return true;
};
};
} |
Hi Berly,
Thank you for responding, but I was getting the below error after trying this code snippet.
Can you please show me a solution for this one.
Thank you,
Lahari Navudu
|
document.querySelector('.e-file-status')!.innerHTML ='File size exceed'; |
|
document.querySelector<HTMLElement>('.e-file-status').style.color ='red'; |
- 9 Replies
- 4 Participants
-
LN Lahari Navudu
- Sep 9, 2021 02:28 PM UTC
- Sep 16, 2021 11:02 AM UTC