我认为我和我的路线有问题。我试图将post变量从同一页面中的模态传递给create.blade.php。
这是我的create.blade.php代码:
<!DOCTYPE html>
<html>
<head>
<title>Crear Detalle</title>
<meta charset="utf-8">
<link rel="stylesheet" href="//codeorigin.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//codeorigin.jquery.com/ui/1.10.2/jquery-ui.min.js"></script>
<link rel="stylesheet" href="{{ asset('css/bootstrap.min.css') }}">
<link rel="stylesheet" type="text/css" href="{{ URL::asset('css/main.css') }}" />
<!--<script type="text/javascript" src="{{ URL::asset('js/jquery-2.1.1.min.js') }}" ></script>-->
<script type="text/javascript" src="{{ URL::asset('js/bootstrap.min.js') }}" ></script>
<!--<script type="text/javascript" src="{{ URL::asset('js/typeahead.js') }}" ></script>-->
</head>
<script>
</script>
<body>
<div class="container">
<nav class="navbar navbar-inverse">
<div class="navbar-header">
<a class="navbar-brand" href="{{ URL::to('nota_detalle') }}">Panel de Detalles de Ordenes</a>
</div>
<ul class="nav navbar-nav">
<li><a href="{{ URL::to('nota_detalle') }}">Ver todos los Detalles</a></li>
<li><a href="{{ URL::to('nota_detalle/create') }}">Crear un Detalle</a>
</ul>
</nav>
<h1>Crear Detalle</h1>
<!-- if there are creation errors, they will show here -->
{{ HTML::ul($errors->all() )}}
{{ Form::open(array('url' => 'nota_detalle', 'class' => '')) }}
<table>
<tr>
<td class="ancho">
<div class="form-group">
{{ Form::label('codigo_nota', 'Codigo Orden') }}
{{ Form::text('codigo_nota', Input::old('codigo_nota'), array('class' => 'form-control')) }}
</div>
</td>
<td class="ancho">
<a href="#" class="btn btn-default"
data-toggle="modal"
data-target="#modalCliente">Buscar</a>
</td>
</tr>
<tr>
<td class="ancho">
<div class="form-group">
{{ Form::label('cantidad_detalle', 'Cantidad') }}
{{ Form::text('cantidad_detalle', Input::old('cantidad_detalle'), array('class' => 'form-control')) }}
</div>
</td>
</tr>
<tr>
<td class="ancho">
<div class="form-group">
{{ Form::label('descripcion_detalle', 'Descripción') }}
{{ Form::textarea('descripcion_detalle', Input::old('descripcion_detalle'), array('class' => 'form-control')) }}
</div>
</td>
</tr>
<tr>
<td class="ancho">
<div class="form-group">
{{ Form::label('precioIVA_detalle', 'Precio con IVA') }}
{{ Form::number('precioIVA_detalle', Input::old('precioIVA_detalle'), array('class' => 'form-control')) }}
</div>
</td>
</tr>
<tr>
<td class="ancho">
<div class="form-group">
{{ Form::label('precioSinIVA_detalle', 'Precio sin IVA') }}
{{ Form::number('precioSinIVA_detalle', null, array('class' => 'form-control', 'size' => '30x4')) }}
</div>
</td>
</tr>
<tr>
<td class="ancho">
<div class="form-group">
{{ Form::label('precioTotal_detalle', 'Precio Total') }}
{{ Form::number('precioTotal_detalle', null, array('class' => 'form-control')) }}
</div>
</td>
</tr>
</table>
{{ Form::submit('Agregar Detalle!', array('class' => 'btn btn-primary')) }}
{{ Form::close() }}
<!-- Modal -->
<div class="modal fade" id="modalCliente" tabindex="-1" role="dialog" aria-labelledby="basicModal" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
{{ Form::open(array('id' => 'formModal', 'url' => '', 'method' => 'POST')) }}
{{ Form::label('auto', 'Escriba el Numero de Chapa: ') }}
{{ Form::text('auto', '', array('id' => 'auto')) }}
<br />
{{ Form::label('response', 'Codigo de la Orden: ') }}
{{ Form::text('response', '', array('id' =>'response', 'disabled' => 'disabled')) }}
<div class="modal-footer">
<button type="submit" id="submitModal" class="btn btn-default" data-dismiss="modal" aria-hidden="true">Seleccionar</button>
</div>
{{ Form::close() }}
</div>
</div>
</div>
</div>
<?php
$array = Input::all();
var_dump($array);
?>
<script type="text/javascript">
$(function() {
$("#auto").autocomplete({
source: "create/getdata",
minLength: 1,
select: function( event, ui ) {
$('#response').val(ui.item.id);
}
});
});
</script>
</body>
</html>
这是我的路线档案:
Route::get('nota_detalle/create/getdata', 'SearchController@index');
Route::post('nota_detalle/create/getdata', 'SearchController@returnValue');
这是我的SearchController文件:
<?php
class SearchController extends BaseController {
public function index()
{
$term = Str::upper(Input::get('term'));
$results = NotaCabecera::select("codigo_nota", "chapa_vehiculo")->where('chapa_vehiculo', 'LIKE', '%'.$term.'%')->get();
//dd($results);
$data = array();
foreach ($results as $result) :
//$data[] = $result->codigo_nota.' '.$result->chapa_vehiculo;
$data[] = array('value' => $result->chapa_vehiculo, 'id' => $result->codigo_nota);
endforeach;
return Response::json($data);
}
public function returnValue()
{
$id = Input::get('id');
return View::make('nota_detalle.create', compact($id));
}
}
如何使用通过Modal Form传递的Id变量填充codigo_nota文本字段?请帮助。
这是它的工作原理:
请帮忙。