我正在构建的页面允许用户将新产品添加到系统中。我在这个页面有一个jQuery问题,页面不会让我继续,除非我上传照片 - 这不应该发生,客户应该能够继续而不上传该项目的照片。产品名称,产品项目代码,类别下拉列表和图像上传文本框。我需要放置一些代码,以便在没有上传图像的情况下单击完成按钮。这是我的代码:
$('#fileupload').fileupload('option', {
autoUpload: false,
singleFileUploads: false,
replaceFileInput: false,
// Enable image resizing, except for Android and Opera,
// which actually support image resizing, but fail to
// send Blob objects via XHR requests:
disableImageResize: /Android(?!.*Chrome)|Opera/
.test(window.navigator.userAgent),
acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
previewMaxWidth: 100,
previewMaxHeight: 100,
previewCrop: true
}).on('fileuploadadd', function (e, data) {
$('#previews').empty();
$("#finish").off('click').on('click', function () {
var sku = $("#productSKU").val();
var name = $("#productName").val();
var affiliateId = $("#AffiliateID").val();
var Errors = "";
var category = null;
var defaultName = $('#defaultImgName').val();
if ($("#childCategories_" + categoryLevel).length == 0) {
category = $("#categoryList").val();
}
else if ($("#childCategories_" + categoryLevel).val() == 0) {
category = null;
}
else {
category = $("#childCategories_" + categoryLevel).val();
}
if (!sku) {
Errors += "<li> You can not add a product without an Item Code</li>";
}
if (!name) {
Errors += "<li> You can not add a product without a Name</li>";
}
if (!category) {
Errors += "<li> You can not add a product without a Category</li>";
}
if (Errors != "") {
cua({ text: Errors, type: 'danger' })
}
else {
data.formData = { productName: name, productSKU: sku, affiliateID: affiliateId, categoryID: category, defaultImgName: defaultName }
data.submit();
}
});
}).on('fileuploadprocessalways', function (e, data) {
var index = data.index,
file = data.files[index],
node = $('#previews');
node.append("<div class=\"img-preview\"></div>");
var innernode = node.find('.img-preview').last();
innernode.append(file.preview);
innernode.attr('data-name', file.name);
var firstImg = node.find('.img-preview').first();
$('.default-img').removeClass('default-img');
firstImg.addClass('default-img');
$('#defaultImgName').val($('.default-img').data('name'));
if (file.error) {
node
.append('<br>')
.append($('<span class="text-danger"></span>').text(file.error));
}
}).on('fileuploaddone', function (e, data) {
if (data.result != false) {
cua({ text: 'Successfully added new item', type: 'success' });
closeAddNew();
}
});
我尝试使用我的chrome开发人员工具对其进行调试,但仍难以隔离此问题。对此问题的任何帮助将不胜感激。
谢谢,
答案 0 :(得分:0)
您需要将图像验证与其他输入字段验证分开。 希望它有所帮助,谢谢;)