我有使用ajax的上传按钮,我希望此操作是必需的,这是代码。
按钮代码:
<div class="form-group">
{!! Form::label('image', 'Image: ', ['class' => 'col-sm-3 control-label required']) !!}
<div class="col-sm-6">
<button class="btn btn-primary" type="button" id="modalgambar" data-toggle="modal" data-target="tambahgambar"></button>
<span id="helpBlock" class="help-block"><i></b></i></span>
</div>
</div>
模态:
<div class="modal fade" id="tambahgambar" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<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"></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"></button>
</div>
</form>
</div>
</div>
</div>
的Ajax:
$('#form-product').submit(function(event) {
if ($("#input-dim-1").val() == '') {
event.preventDefault();
alert("Image Is Required");
} else {
if(! validationInput()) {
form.submit();
}
alert('Stok tidak boleh minus');
}
return false;
});
当我没有上传图片时出现警报(&#34;图像是必需的&#34;),但是当我上传图片时也出现警报,因此令人困惑。 :( 有人能帮我吗? 我试着找到解决方案,但我还没找到它:(