我想要求上传图片按钮
这是我认为的代码

模态

<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">&times;</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
    });


阿贾克斯

$('#form-product').submit(function(event) {
     if ($("#input-dim-1").val() == '') {
       event.preventDefault();
       alert("Image Is Required");
     } else {
       form.submit();
       }
       return false;
     });


现在,当用户未上传图像时,将显示要求,但是当用户上传图像时,也会显示:
有人能帮我吗?

谢谢

最佳答案

你有:

<input id="input-dim-1" name="inputdim1[]" type="file" multiple class="file-loading" accept="image/*">


后端使用laravel时,您可以像这样验证所需的数组输入:

'inputdim1.*' => 'required'


在HTML方面,您可以添加必填属性:

<input id="input-dim-1" name="inputdim1[]" type="file" multiple class="file-loading" accept="image/*" required>

10-01 19:05