Laravel AJAX Form在提交验证时丢失了值

时间:2015-04-16 10:32:20

标签: jquery ajax validation laravel-4 blade

我是大家!
在我的页面中,我有一个select元素,可以选择填充已确定的表单,它会填充@include('pergunta.pergunta')的更新。
这是形式:

@if ($errors->has())
    <div class="alert alert-danger">
        {{ HTML::ul($errors->all()) }}
    </div>
@endif
{{ Form::open(array('action' => 'AController@store','id'=>'formA')) }}
    <table>
        <tbody>
            <tr>
                <td>
                {{ Form::label('modelo', 'Modelo') }}
                {{-- MY SELECT ELEMENT --}}
                <div class="form-group @if ($errors->has('modelo')) has-error @endif">
                    <select id="sModelo" name="modelo" class="form-control" style= "width: 150px">
                        <option value="" disabled selected> Modelo </option>
                        @foreach ($modelos as $modelo)
                            <option value="{{$modelo->id }}">  {{$modelo->nome }}</option>
                        @endforeach
                    </select>
                </div>
                </td>
            </tr>    
        </tbody>
    </table>
        ...
        <div class="form-group @if ($errors->has('user')) has-error @endif">
            <select class="form-control" name="user">
                <option value="" disabled selected>User</option>
                @foreach ($users as $key => $value)
                    <option value="{{$value->id}}">{{ $value->nome }}</option>
                @endforeach
            </select>
        </div>
        ...
        <select class="form-control" name="user2">
            <option value="" disabled selected>User2</option>
            @foreach ($user2 as $key => $value)
                <option value="{{$value->id}}">{{ $value->nome }}</option>
            @endforeach
        </select>
        {{ Form::label('', Auth::user()->nome ,array('class' => 'labels')) }}
        <!-- Descriçao da Situação -->
        <table class="table table-bordered table-condensed alinhar">
            <tbody>
                <tr>
                    <td class="titulo" style="width:250px;">Descriçao</td>
                    <td>
                    <div class="form-group @if ($errors->has('situacao')) has-error @endif">
                        {{ Form::textarea('situacao', null, ['placeholder' => 'Descrição da Situação', 'class' => 'form-control','size' => '30x1']) }}
                    </div>
                    </td>
                </tr>
            </tbody>
        </table>
        --> THIS IS WHAT IS GOING TO BE UPDATED
        <!-- Blocos Perguntas -->
        <table id="updateTable" class="table table-bordered table-condensed alinhar">
            @include('pergunta.pergunta')
        </table>

我的AJAX功能在js文件中:

    $("#sModelo").on('change', function(e){
        var idModelo = e.target.value;
        $('#updateTable').load('/admin/a/pesquisa/' + idModelo);
    });

我的控制器:

public function store()
{
    if (!$this->audit->isValid(Input::all())) {
        return Redirect::back()->withInput()->withErrors($this->audit->errors);
    }
    ...
    return Redirect::action('AController@index');
}

每次我提交表单时,我都会在主页面中填写未填写或不正确的字段,我会通过laravel服务获取页面中的通知,但是我丢失了由ajax提交的页面以及所有填充的值。如何在不先进入服务器并验证的情况下对文本框进行客户端验证并选择元素?

0 个答案:

没有答案