Form and Upload validation

0 Answers 53 Views
Form Upload Validation
Daniel
Top achievements
Rank 1
Iron
Iron
Iron
Daniel asked on 16 Sep 2024, 11:39 PM

Hi,

We've using a Form component with an Upload component in it. The validation within the Upload works fine but we'd like to check whether a file has been uploaded and / or selected. The "required" part of the Form validation doesn't seem to trigger when no file is selected. Code provided is an item in the Form.

                    {
                        field: "mailingList",
                        label: "Mailing List",
                        colSpan: 2,
                        editor: function (container, options) {
                            $('<input type="file" name="' + options.field + '" id="' + options.field + '"/>').appendTo(container)
                                .kendoUpload({
                                    async: {
                                        saveUrl: "/rates-notices-campaign/save-attach/" + id,
                                        removeUrl: "/rates-notices-campaign/remove-attach/" + id,
                                        autoUpload: true
                                    },
                                    validation: {
                                        allowedExtensions: [".csv", ".xlsx"]
                                    }
                                });
                        },
                        validation: {
                            required: {
                                message: "Mailing List is required"
                            }
                        }
                    }

 

Thanks

Neli
Telerik team
commented on 19 Sep 2024, 09:24 AM

Hi Daniel,

- You could take a look at the article linked below regarding validation of the Upload component:

https://docs.telerik.com/kendo-ui/knowledge-base/upload-file-selected-validation

In scenario when the Upload is placed in a Form instead of initializing a new Kendo Validator, you can try using the one that is already initialized from the Kendo Form:

var validator = $("#form").getKendoForm().validator;

- Another approacch is demonstrated in the dojo linked here - https://dojo.telerik.com/@NeliK/AXidulOj

I will also encourage you to cast a vote in the following Feature request item for adding the Upload component to the built-in Form editors:

- https://feedback.telerik.com/kendo-jquery-ui/1539630-support-the-upload-as-an-editor-in-the-form

I hope this helps. 

 

Regards,

Neli

Daniel
Top achievements
Rank 1
Iron
Iron
Iron
commented on 19 Sep 2024, 10:28 PM

Hi Neli,

We went with the second approach and works well. A bit hacky but works better than the more standard approach.

Thanks

Neli
Telerik team
commented on 24 Sep 2024, 08:06 AM

Hi Daniel,

I am glad that the suggestions were helpful in achieving the desired result.

Feel free to contact us in case you have any additonal question on the matter.

Regards,

Neli

No answers yet. Maybe you can help?

Tags
Form Upload Validation
Asked by
Daniel
Top achievements
Rank 1
Iron
Iron
Iron
Share this question
or