gpt4 book ai didi

javascript - 如何使用 proengsoft/laravel-jsvalidation 和 Laravel 5 验证数组输入

转载 作者:行者123 更新时间:2023-12-02 14:09:51 24 4
gpt4 key购买 nike

您好,我正在尝试验证数组输入并选择如下:

<td width="23%">                                            
{!!Form::select('mmscod_id[]',['' => '- Seleccione un material -'] +$mat,null,['class' => 'form-control', 'id'=>'mmscod_id'])!!}
</td>

<td width="17%">
<input type="text" class="form-control" id="cantidad" name="vtcanp[]"/>

</td>
<td width="17%">
<input type="text" class="form-control" id="precio" name="vtprep[]"/>
</td>

我正在使用proengsoft/laravel-jsvalidation用于客户端验证。对于后端,我使用 Laravel 的表单请求。

我也是用这个网站的方法:How To: Validate an array of form fields with Laravel但它不起作用并抛出错误:

error1

error2

编辑:我忘了提及这些元素是动态创建的请帮助我

最佳答案

Laravel 支持验证数组输入。您需要使用此约定来验证数组项。

$rules = [
'vtcanp.*' => 'required',
];

例如:

这是我的自定义请求类

class InvoiceRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
$rules =[
'client' => 'required',
'date' => 'required',
'total' => 'required',
'discount' => 'required',
'item.*' => 'required',
'rate.*' => 'required',
'quantity.*' => 'required',


];


return $rules;
}
}

并在 View 中添加

{!! JsValidator::formRequest('App\Http\Requests\InvoiceRequest') !!}

这些验证并显示错误消息以及我动态添加到 View 中的输入数组的位置。

关于javascript - 如何使用 proengsoft/laravel-jsvalidation 和 Laravel 5 验证数组输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39709997/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com