Validate if file is selected for upload

4 posts, 0 answers
  1. Anamika
    Anamika avatar
    157 posts
    Member since:
    Mar 2014

    Posted 30 Aug Link to this post

    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

  2. Ivan Danchev
    Admin
    Ivan Danchev avatar
    1332 posts

    Posted 01 Sep Link to this post

    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.
  3. Anamika
    Anamika avatar
    157 posts
    Member since:
    Mar 2014

    Posted 04 Sep in reply to Ivan Danchev Link to this post

    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>

     

  4. Ivan Danchev
    Admin
    Ivan Danchev avatar
    1332 posts

    Posted 06 Sep Link to this post

    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.
Back to Top