Selected image information deleted if to big..

rbuelund

Member
I have a form with repeated group. Each added group contains 3 fileupload elements with limit of 1,5 MB. The selected image information is removed if one of the images are to big upon upload - can this in any way be avoided, so that one not has to select all images all over if one is too big ? I know that Ajax could validate befor upload, but you have earlier told that ajax is not supported with repeat groups ?
 
I managed to create a javascript on each fileupload element that checks the size on change:

var fileUpload = document.querySelectorAll('[id^="nfo2fabrik_killinger_65_repeat___image_1"]');
[].forEach.call(fileUpload, function (e){
if (e.files !== null) {
if (e.value !== ''){
var size = parseFloat(e.files[0].size / 1024).toFixed(2);
if(size > 1499)
{
alert("The image you have selected is bigger thanbj 1500 KB ! Size is: " + size + " KB. Please select another image less than 1500 KB");
e.value = '';
}
}
}
});
 
Just made the script a little better. Now it also resets the preview image:

var maxsize = 1500;
var fileUpload = document.querySelectorAll('[id^="nfo2fabrik_killinger_65_repeat___image_1"]');
[].forEach.call(fileUpload, function (e){
if (e.files !== null) {
if (e.value !== ''){
var size = parseFloat(e.files[0].size / 1024).toFixed(2);
if(size > maxsize)
{
alert("The image you just selected is bigger than "+maxsize+" KB ! The size is: " + size + " KB. Please select another image that is smaller than "+maxsize+" KB");
alert(e.parentElement.className);
e.value = '';
var tempimage = e.parentElement.getElementsByTagName('img');
tempimage[0].src = "/";
var tempimagespan = e.parentElement.getElementsByTagName('span');
tempimagespan[0].classList.add("fabrikHide");
}
}
}
});
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top