1

I am adding an additional field to allow the user to specify a photo caption before uploading. I want to make this filed a required input. I can;t find anything in the documentation the provides validation. So i have put together the following code

$('#fileupload').bind('fileuploadsubmit', function(e, data) {
                var inputs = data.context.find(':input.form-control');

                if (inputs.val() == "")
                {
                    return false;
                }


            });

This allows me to check the value being passed by the caption field and asses it. if I return false it does stop the the form submitting. but it disables the upload button and this can't be re enabled.

Also I can't find a way of displaying an error message to the use.

Am I going about this the wrong way? is there in fact an method for doing client side validation on the additional form data that i have missed?

Thanks

EDIT

I forgot to mention in the main post. I am using the component https://github.com/blueimp/jQuery-File-Upload

3
  • Where do you handle the form submit? In a separate function, bound to the .submit() event? Then, you could move this to a named function (eg SubmitPhoto()) and call it when the form validates. Then, to prevent the submit button from going into a disabled state, edit your code (in your question) and add e.preventDefault(); to the beginning. Commented Apr 28, 2014 at 13:58
  • The form submit is handle by the jquery file upload plugin. I am using the callbacks supplied to try and do some rudimentary validation. Commented Apr 28, 2014 at 19:51
  • Already has an answer for your question in this topic: Jquery file upload plugin: how to validate files on add? Commented Jan 6, 2016 at 21:16

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.