我有这段代码:
<!-- line modal -->
<div class="modal fade" id="squarespaceModal" tabindex="-1" role="dialog" aria-labelledby="modalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title" id="lineModalLabel">Prašymas Dėl Pakvietimo</h3>
</div>
<div class="modal-body">
<!-- content goes here -->
@if($errors->any())
@foreach($errors->all() as $error)
<ul class="list-unstyled">
<li class="alert alert-danger">{{$error}}</li>
</ul>
@endforeach
@endif
{!! Form::open(['url' => 'sukurti', 'id' => 'frm']) !!}
@include('components.forma')
{!! Form::close() !!}
</div>
</div>
</div>
</div>
&#13;
我想在这里做的是在不关闭模态的情况下显示错误。因为如果现在我留下空格并按提交,模式关闭,如果我再次按下按钮以显示模态,我可以看到错误。如何制作当空格空白我按下输入模态不会关闭,只是留下但有错误?
答案 0 :(得分:0)
要像这样工作,你必须在代码中进行一些调整。
Jquery将处理您的提交操作。提交一个提交事件;
$('#frm').submit(function(e){
//stop default submit
e.preventDefault();
//make checks here now check for space .
var field = trim($('fieldname').val());
//of course you can apply some jquery validation library here too .
if(field.length > 0){
//submit form but you need to perform ajax for saving data here
//on ajax success close you modal
//here if you have some server side validation error then show them here without closing modal
//laravel give you error in json array form . foreach and append them on ul tag .
//$error = []; $.each(errors , function(val){$error[] = "<li>"+val+"</li>";}); $('ulid or class').html(error);
//empty html of this ulid or class if there is no error
// $('#squarespaceModal').modal('hide');
}else{
//show error
$('ulid or class').html('<li>This is error</li>');
}
})
这是基本的想法,如何实现目标。