[英]How to make Required on Upload Image Button
i want to make require for image upload button this is the code on my view 我想要图片上传按钮这是我视图上的代码
Modal 语气
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Unggah Gambar</h4>
</div>
<form id="upload-image" enctype="multipart/form-data">
<div class="modal-body">
<input id="input-dim-1" name="inputdim1[]" type="file" multiple class="file-loading" accept="image/*">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Keluar</button>
</div>
</form>
</div>
$("#input-dim-1").fileinput({
uploadExtraData: {_token:"{{csrf_token()}}", key : key},
uploadUrl: "{!! route('admin.product.getupload') !!}",
allowedFileExtensions: ["jpg", "png", "jpeg"],
minImageWidth: 50,
minImageHeight: 50,
maxFileCount: 5
});
Ajax 阿贾克斯
$('#form-product').submit(function(event) {
if ($("#input-dim-1").val() == '') {
event.preventDefault();
alert("Image Is Required");
} else {
form.submit();
}
return false;
});
Now the required is appears when user not uploaded image, but this appear too when user have uploaded image :( can someone help me? 现在,当用户没有上传图片时,会出现所需的内容,但是当用户上传图片时也会显示:(有人可以帮我吗?
thanks 谢谢
You have: 你有:
<input id="input-dim-1" name="inputdim1[]" type="file" multiple class="file-loading" accept="image/*">
Backend side when using laravel you could validate the array input to be required like so: 使用laravel后端方面你可以像这样验证数组输入是否需要:
'inputdim1.*' => 'required'
Html side you could add required attribute: Html方面你可以添加必需的属性:
<input id="input-dim-1" name="inputdim1[]" type="file" multiple class="file-loading" accept="image/*" required>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.