This is a migrated thread and some comments may be shown as answers.

Validate if file is selected for upload

3 Answers 1128 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Anamika
Top achievements
Rank 1
Anamika asked on 30 Aug 2017, 02:55 PM

hello,

 

i am using Kendo upload control in a form which has many other controls and on submit click in jquery i Need to validate if any file is selected for upload. If no files selected i should Show message. I am trying this

var upload =$(#files").find('kendoUpload');

var len = upload.closest(".k-upload").find(".k-file").length;

if(len === 0){

alert('please select file');

}

 

doesnt seem to work.

How can i validate in jquery.

 

Thanks

 

Anamika

3 Answers, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 01 Sep 2017, 10:30 AM
Hello Anamika,

Here's a dojo example, which shows how you can use the Kendo UI Validator to prevent the form submit and display a message if no file is selected in the Upload.

Regards,
Ivan Danchev
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Anamika
Top achievements
Rank 1
answered on 04 Sep 2017, 08:24 AM

Thanks Ivan for the sample. I get validator.validate() as undefined. Any idea what could be causing that. In my Layout.cshtml file the included js files are

<script src="//da7xgjtj801h2.cloudfront.net/2017.2.621/js/jszip.min.js"></script>
<script src="//da7xgjtj801h2.cloudfront.net/2017.2.621/js/jquery.min.js"></script>
<script src="//da7xgjtj801h2.cloudfront.net/2017.2.621/js/kendo.all.min.js"></script>

 

0
Ivan Danchev
Telerik team
answered on 06 Sep 2017, 06:40 AM
Hello Anamika,

Are you initializing the Validator from your form element prior to calling its validate method (validator.validate())?
var validator = $("#myForm").kendoValidator({
    rules: {
        upload: function(input) {
            if (input[0].type == "file") {
                fileNotSelected = true;
                var len = input.closest(".k-upload").find(".k-file").length;
                return len > 0;
            }
           
            return true;
        }
    }
}).data("kendoValidator");

Note that "myForm" has to be replaced with your form's id. After this initialization the "validator" variable should hold a reference to the Validator.

Regards,
Ivan Danchev
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Paul
Top achievements
Rank 1
Veteran
commented on 20 May 2021, 03:50 PM

Hi Ivan,

Would you have an example of how to achieve this using jQuery Validate validator?

Thanks,

Paul
Viktor Tachev
Telerik team
commented on 25 May 2021, 08:14 AM

jQuery validation is not part of the Kendo suite and because of that we do not have specific examples for it. Nevertheless, if you would like to use jQuery validate I suggest checking out the setting up video for it and also the official documentation.

That said, I would recommend using the Kendo validator widget as it was built having in mind integration with the other Kendo widgets.

Tags
Upload
Asked by
Anamika
Top achievements
Rank 1
Answers by
Ivan Danchev
Telerik team
Anamika
Top achievements
Rank 1
Share this question
or