Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 记住数据表中的下拉列表和验证字段_Jquery_Laravel_Datatable_Blade_Dropdown - Fatal编程技术网

Jquery 记住数据表中的下拉列表和验证字段

Jquery 记住数据表中的下拉列表和验证字段,jquery,laravel,datatable,blade,dropdown,Jquery,Laravel,Datatable,Blade,Dropdown,第一个疑问是,当我需要返回浏览器时,如何记住所选的下拉列表?我有几个字段,我把所需的数据,并选择所有的下拉列表。如果有一些错误,重定向到同一页与具体的错误和所有字段完成,但下拉列表没有,我必须再次选择。这很烦人。。 我用的是带刀片的拉威尔。我的选择的一个例子是下一个: <div class="form-group"> <label class="col-md-3 control-label" for="country_id"> {{{ trans(

第一个疑问是,当我需要返回浏览器时,如何记住所选的下拉列表?我有几个字段,我把所需的数据,并选择所有的下拉列表。如果有一些错误,重定向到同一页与具体的错误和所有字段完成,但下拉列表没有,我必须再次选择。这很烦人。。 我用的是带刀片的拉威尔。我的选择的一个例子是下一个:

<div class="form-group">
            <label class="col-md-3 control-label" for="country_id"> {{{ trans('provider.countries') }}} <span class="required">*</span></label>
            <div class="col-md-6">
                <div class="input-group btn-group">
                    <span class="input-group-addon">
                        <i class="fa fa-th-list"></i>
                    </span>
                    {!! Form::select('country_id', $countries, old('country_id'), array('class' => 'form-control', 'required', 'id' => 'select_country', 'placeholder'=>'Seleccione un País', 'autocomplete'=>'off')) !!}
                </div>
            </div>
        </div>

{{{trans('provider.countries')}}}*
{!!Form::select('country\u id',$countries,old('country\u id'),array('class'=>'Form control','required','id'=>'select\u country','placeholder'=>'Seleccione un País','autocomplete'=>'off'))
另一方面,我得到了一个包含4列的数据表,1列包含select,2列包含输入编号。当我添加第一行时,字段验证工作正常,但当我添加多行时,此验证不工作。。 代码是下一个

<div class="table-responsive table-striped table-bordered table-condensed">
    <table class="table table-receipts invoice-items" id="receipt-table">
      <thead>
        <tr class="h5 text-dark">
          <th id="cell-item" class="text-weight-semibold vertical-center">Producto</th>
          <th id="cell-store" class="text-center text-weight-semibold absolute-center">Sucursal</th>
          <th id="cell-price" class="text-center text-weight-semibold absolute-center">Precio Unitario</th>
          <th id="cell-qty" class="text-center text-weight-semibold absolute-center">Cantidad</th>
          <th id="cell-delete" class="text-center text-weight-semibold absolute-center">Acciones</th>
        </tr>
      </thead>
      <tbody>
        <tr class="hide default-row-product">
          <td class="col-md-4 text-weight-semibold text-dark vertical-center">
            <input type="hidden" name="products[]">
          </td>
          <td class="col-md-2 text-center">
            {!! Form::select('stores[]', $stores, '', array('class' => 'form-control', 'required', 'placeholder'=>'Seleccionar', 'id'=>'stores_id')) !!}
          </td>
          <td class="col-md-1 text-center">
            <input type="number" name="prices[]" class="form-control" min="1" step="0.1" id="prices_id" required>
          </td>
          <td class="col-md-1 text-center">
            <input type="number" name="quantities[]" class="form-control" min="1" step="0.1" id="quantities_id" required>
            <td class="col-md-1 text-center">
              <button type="button" class="mb-xs mt-xs mr-xs btn btn-xs btn-danger" id="button-delete-product"><i class="fa fa-trash"></i></button>
            </td>
          </tr>
        </tbody>
      </table>
    </div>

产品
成功的
普瑞西奥尤塔里奥酒店
康蒂达
疫苗
{!!Form::select('stores[]'、$stores',array('class'=>'Form control','required','placeholder'=>'selecciator','id'=>'stores_id'))

问候

第一个问题的答案: 您必须将所选选项存储在本地存储或cookie中:

// store value in local storage
$('select[name="country_id"]').change(function() {
    localStorage.setItem('selected', this.value);
});

// restore selected value from local storage after page was loaded
if(localStorage.getItem('selected')){
    $('select[name="country_id"]').val(localStorage.getItem('selected'));
}
或者您可以使用会话。在控制器中,验证数据后将所选选项放入会话中

if($validator->fails) {
    return Redirect:to('/form')->with('selected', Input::get('question_id');
}
并在视图中使用jQuery:

@if(Session::has('selected')
$(document).ready(function() {
   $('select[name="country_id"]').val("{{ Session::get('selected') }}");
});
@endif    
编辑: 输入(价格)数组的验证:

$prices=Input::get('prices');
//为每个价格输入创建数组

对于($i=0;$i第一个问题的答案: 您必须将所选选项存储在本地存储或cookie中:

// store value in local storage
$('select[name="country_id"]').change(function() {
    localStorage.setItem('selected', this.value);
});

// restore selected value from local storage after page was loaded
if(localStorage.getItem('selected')){
    $('select[name="country_id"]').val(localStorage.getItem('selected'));
}
或者,您可以使用会话。在控制器中,验证数据后将选定选项放入会话中

if($validator->fails) {
    return Redirect:to('/form')->with('selected', Input::get('question_id');
}
并在视图中使用jQuery:

@if(Session::has('selected')
$(document).ready(function() {
   $('select[name="country_id"]').val("{{ Session::get('selected') }}");
});
@endif    
编辑: 输入(价格)数组的验证:

$prices=Input::get('prices');
//为每个价格输入创建数组

对于($i=0;$i Hi,感谢您的回复。我稍后会尝试您的代码。查看datatable tbody,每个字段都需要值的间隔。当我添加第二行时,此验证无效。我确认表单,重定向页面,然后显示请求的错误验证。Hi,感谢您的回复。我稍后会尝试您的代码。Lo在datatable tbody中,每个字段都需要值的间隔。当我添加第二行时,这种验证不起作用。我确认表单,重定向页面,然后显示请求的错误验证。