[英]How to refresh page in modal
JS: JS:
function createNewCategory(idx){
$('#category').modal('show');
var modal = $('#category').modal();
$('.ok').unbind().click(function(){
modal.find('form').ajaxSubmit({
url: "<?php echo url('/category') ?>",
type: "POST",
dataType : 'json',
success : function(data){
var app = '<option selected="" value="'+data.CategoryID+'">'+data.CategoryName+'</option>';
$('.cats-' + idx).append(app);
$('.cats-' + idx).multiselect();
}
});
modal.modal('hide');
});
return false;
}
Modal Form (HTML) 模态形式(HTML)
<div class="modal fade" id="category">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Kategori baru</h4>
</div>
<div class="modal-body">
<form class="form-horizontal" id="category-form" enctype="multipart/form-data">
{{ csrf_field() }}
<div>
<ul class="nav nav-tabs language" role="tablist" id="myTab" >
@foreach($languages as $language)
<li name="LanguageName" class="{{$language->id == 1 ? 'active' : ''}}"><a href="#catlang-{{$language->id}}" data-toggle="tab">{{$language->LanguageName}}</a></li>
@endforeach
</ul>
<div class="tab-content">
@foreach($languages as $language)
<div class="tab-category tab-pane fade {{$language->id == 1 ? 'in active' : ''}}" id="catlang-{{$language->id}}">
<label>Nama Kategori <span class="required">*</span></label>
<input type="text" name="CategoryName[{{$language->id}}]" class="form-control" required></input>
</div>
@endforeach
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary ok">OK</button>
</div>
</div>
</div>
</div>
After I input something in "input text" then I close and I open the modal again.. The modal page does not refresh and It makes me get the value of input text before.. How to refresh the modal? 在“输入文本”中输入内容后,我关闭并再次打开模态。.模态页面不刷新,这使我之前获得了输入文本的值。如何刷新模态?
You need to clear all fields in modal. 您需要清除模式中的所有字段。 As answered in Clear modal fields after close it
如关闭后在清除模式字段中所回答
Just use one-type selector on each modal window field 只需在每个模式窗口字段上使用一种类型的选择器
You can clean the inputs when the modal is shown, you just have to wait for the event "shown". 显示模态时,您可以清除输入,只需等待事件“显示”即可。 First, add a class to your inputs, so we can clean it later:
首先,将一个类添加到您的输入中,以便我们稍后对其进行清理:
@foreach($languages as $language)
<div class="tab-category tab-pane fade {{$language->id == 1 ? 'in active' : ''}}" id="catlang-{{$language->id}}">
<label>Nama Kategori <span class="required">*</span></label>
<!-- Please note: I add a class "clean-modal" -->
<input type="text" name="CategoryName[{{$language->id}}]" class="form-control clean-modal" required></input>
</div>
@endforeach
Then, wait for the modal to be shown. 然后,等待显示模态。 And inside the function clean the inputs
并在函数内部清理输入
$('#category').on('shown.bs.modal', function() {
$(".clean-modal").val(""); //We empty the inputs with the class "clean-modal"
})
Hope this helps 希望这可以帮助
Use submit button in place of button it will reload the page as it submits the form 使用提交按钮代替按钮,它将在提交表单时重新加载页面
<button id="yourID" class="btn btn-primary" type="submit">Send</button>
or without any modification use the simplest way to hide a modal 或不做任何修改就使用最简单的方法来隐藏模态
$('#category').modal('hide');
along with this you can Clear modal fields after close it like mentioned by Jukka :) 与此同时,您也可以像Jukka所说的那样, 在关闭模态字段后清除它 :)
通过使用JavaScript的重置功能,只需在隐藏模式之前重置表单即可解决您的问题。
$('form')[0].reset();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.