Phi*_*hil 5 laravel bootstrap-dialog
我想返回我的模态对话框编辑表单以显示验证错误,但使用Redirect::back我最终在没有模态窗口的HTML页面.
我使用BootstrapDialog 将我的attendee.edit路线加载到弹出编辑表单的模态对话框中.
HTML
<td>{{link_to_route('attendee.edit','',array($attendee->id), array(
'class'=>'edit-attendee btn btn-info btn-xs glyphicon glyphicon-pencil',
'data-title' => 'Edit Attendee'))}}
</td>
Run Code Online (Sandbox Code Playgroud)
JQuery调用BootstrapDialog
$(document).ready(function(){
$('.btn.edit-attendee').click(function(e){
e.preventDefault();
url = $(this).attr('href');
BootstrapDialog.show({
title: $(this).data('title'),
message: $('<div></div>').load(url),
buttons: [{
label: 'Update',
action: function(dialogRef) {
$('form').submit();
}
}]
});
});
});
Run Code Online (Sandbox Code Playgroud)
调节器
public function update($id)
{
$attendee = Attendee::findOrFail($id);
$validator = Validator::make($data = Input::all(), Attendee::$rules);
if ($validator->fails())
{
return Redirect::back()->withErrors($validator)->withInput();
}
$attendee->update($data);
return Redirect::route('attendees.index');
}
Run Code Online (Sandbox Code Playgroud)
在我编辑表单后,我想返回到模态窗口以显示验证错误,但我最终只是在没有对话框的HTML页面上.如何重定向回模态窗口?
UPDATE
添加id到控制器返回
return Redirect::back()->withErrors($validator)->withInput()->with('id', $id);
Run Code Online (Sandbox Code Playgroud)
添加了Jquery
@if(!empty(Session::get('id')))
$(document).ready(function(){
url = "{{ URL('attendee') . '/' . Session::get('id'). '/edit' }}";
BootstrapDialog.show({
title: $(this).data('title'),
message: $('<div></div>').load(url),
buttons: [{
label: 'Update',
action: function(dialogRef) {
$('form').submit();
}
}]
});
});
@endif
Run Code Online (Sandbox Code Playgroud)
如果出现错误,则重新打开模态窗口,否则返回.我不喜欢它如何关闭并重新打开模态,并且验证错误没有传递给模态,所以我不建议这样做.
Zac*_*man 13
我刚刚做了这样的事情.你只需要使用刀片的模板!
//pass back a variable when redirecting
return Redirect::back()->with('error_code', 5);
Run Code Online (Sandbox Code Playgroud)
然后在您的刀片模板中:
@if(!empty(Session::get('error_code')) && Session::get('error_code') == 5)
<script>
$(function() {
$('#myModal').modal('show');
});
</script>
@endif
Run Code Online (Sandbox Code Playgroud)
这将创建一个脚本,只要error_code存在且等于5,就会打开对话框!
| 归档时间: |
|
| 查看次数: |
23580 次 |
| 最近记录: |