剑道UI上传错误,添加无效的文件类型时不触发



由于某种原因,当我添加一个无效的文件扩展名时,错误事件没有发生。我是不是忽略了什么?

$(document).ready(() => {
IniUploadJSONFile();
});
function IniUploadJSONFile() {
$("#ImportJSONOrderFile").empty();
$("#ImportJSONOrderFile").kendoUpload({
async: {
//saveUrl: ImportQuote,
autoUpload: false,
multiple: false
},
validation: {
allowedExtensions: [".json"]
},
error: onError
});
}
function onError(e) {
var files = e.files;
for (var i = 0; i < files.length; i++) {
alert("Validation failed for " + files[i].name);
var uid = files[i].uid;
var entry = $(".k-file[data-uid='" + uid + "']");
if (entry.length > 0) {
entry.remove();
}
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2022.1.412/styles/kendo.common.min.css">
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2022.1.412/styles/kendo.rtl.min.css">
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2022.1.412/styles/kendo.default.min.css">
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2022.1.412/styles/kendo.mobile.all.min.css">

<script src="https://kendo.cdn.telerik.com/2022.1.412/js/jszip.min.js"></script>
<script src="https://kendo.cdn.telerik.com/2022.1.412/js/kendo.all.min.js"></script>

<input id="ImportJSONOrderFile" type="file" />

这里是一个只接受.json文件扩展名的示例。您可以在Telerik DOJO中运行它。

<!DOCTYPE html>
<html>
<head>
<base href="https://demos.telerik.com/kendo-ui/datetimepicker/index">
<style>html { font-size: 14px; font-family: Arial, Helvetica, sans-serif; }</style>
<title></title>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://kendo.cdn.telerik.com/2022.1.412/js/kendo.all.min.js"></script>
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2022.1.412/styles/kendo.common.min.css">
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2022.1.412/styles/kendo.rtl.min.css">
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2022.1.412/styles/kendo.default.min.css">
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2022.1.412/styles/kendo.mobile.all.min.css">
</head>
<body>
<div id="example">
<div class="demo-section k-content">
<input id="ImportJSONOrderFile" type="file" />
</div>

<script>
$(document).ready(() => {
IniUploadJSONFile();
});
function IniUploadJSONFile() {
$("#ImportJSONOrderFile").empty();
$("#ImportJSONOrderFile").kendoUpload({
async: {
//saveUrl: ImportQuote,
autoUpload: false,
multiple: false
},
select: function(e) {
$.each(e.files, function (index, value) {
if (value.extension != ".json") {
alert("Invalid file type.");
e.preventDefault();
}
});
},
});
}
</script>

</div>
</body>
</html>

相关内容

  • 没有找到相关文章

最新更新