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
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
Hi Neli,
We went with the second approach and works well. A bit hacky but works better than the more standard approach.
Thanks
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