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

Can't get plugin validation errors #810

Closed
benoitproxi opened this issue Dec 1, 2016 · 4 comments
Closed

Can't get plugin validation errors #810

benoitproxi opened this issue Dec 1, 2016 · 4 comments

Comments

@benoitproxi
Copy link

Hello,

I'm sending my files through ajax but when the upload fails (as with height too small) I don't get the real error message, but I get an error from my ajax url, but this one makes no sense since nothing is sent.
I think the ajax route shouldn't be called, but anyway, I tried to play with 'fileuploaderror' and I do get the wanted errors, but I don't know how to display them. There must be a simple way in the fileuploaderror event, but I don't know it.
Can anyone help me with this one ?

Thanks


$("#id").fileinput({
	uploadUrl: "/ajax/snippet/image/send/78", // server upload action
	deleteUrl: "/ajax/snippet/image/remove/",
	uploadAsync: false,
	showUpload: false, // hide upload button
	showRemove: false, // hide remove button
	maxFileCount: maxFile,
	browseOnZoneClick: true,
	language: "fr",
	minImageWidth: 150,
	minImageHeight: 150,
	allowedFileExtensions: ["jpg", "jpeg", "gif", "bmp", "png"],
	multiple: true,
	maxFileSize: 5000,
	uploadExtraData: function (previewId, index) {
		return {key: index};
	},
	initialPreviewAsData: true,
	overwriteInitial: false,
	}).on("filebatchselected", function (event, files) {
		// trigger upload method immediately after files are selected
		$(this).fileinput("upload");
	}).on('fileuploaderror', function (event, data, msg) {
		var form = data.form, files = data.files, extra = data.extra,
				response = data.response, reader = data.reader;
		// get message
		alert(msg);
	});
}
@kartik-v
Copy link
Owner

kartik-v commented Dec 1, 2016

If it is a plugin validation error it should be displayed.

It seems you are getting an error in your server validation (correct me if I am wrong)... and for that you need to pass the relevant error message in your ajax response to be displayed by the plugin,

@benoitproxi
Copy link
Author

When my image is too big or the width or height are too small, nothing is sent, my ajax url get Null and at this point I don't know if I can get something else from the plugin.
When my image is valid, I get the file from the plugin and the image is correctly uploaded.
Is it a normal behavior for the plugin to send an ajax request with null when the image isn't validated by the plugin ?

@kartik-v
Copy link
Owner

kartik-v commented Dec 2, 2016

As I mentioned, if you are using plugin's maxFileSize validation capability then on error it will display validation message. It will NOT send any data for upload to your ajax URL by default. The validation error is thrown at the file read stage itself. Refer here.

The problem is in your JS code whereby, you are auto triggering upload method in the filebatchselected event (which calls ajax url). This will call the ajax url every time after files are selected. You may want to do a check using getFilesCount or getFileStack to see if files exist before triggering the auto upload in the filebatchselected event.

@benoitproxi
Copy link
Author

Okay, thank you, it's working fine with getFileStack ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants