Ad
How To Set Required Validation For Inner Field Of Repeater In OctoberCMS?
I have tried below code but it's not working for me.
fields.yaml
fields:
repetor_name:
label: Repeater
prompt: 'Add new item'
span: auto
type: repeater
required: 1
form:
fields:
required_text:
label: Text
span: auto
required: 1
type: text
Model
public $rules = [
'repetor_name' => 'required',
'required_text' =>'required'
];
Please Share your knowledge with me if anyone has the solution for it. Thanks
Ad
Answer
You can add Below code in model file
public $rules = [
'repetor_name' => 'required', //repeater field is required
// 'required_text' =>'required' You have to remove this line
];
/* We have to create custom function in model to validate inner fields of repeater*/
public function beforeValidate()
{
foreach ($this->repetor_name as $key => $value) {
$this->rules['repetor_name.'.$key.'.required_text'] = 'required';
}
Ad
source: stackoverflow.com
Related Questions
- → Validating fileupload(image Dimensions) in Backend Octobercms
- → DropzoneJS & Laravel - Output form validation errors
- → laravel check between 2 integer from database
- → How can I use rules method with formRequest in Laravel Js Validation?
- → Is it possible to turn off JavaScript for some tests using Codeception?
- → How to set required validation for inner field of repeater in OctoberCMS?
- → Model Validation in laravel 5.1 not working
- → Issues with jQuery Validate onkeyup and highlighting
- → Laravel validation required rule not working
- → Nested array validation laravel
- → How to change Laravel Validation message for max file size in MB instead of KB?
- → Backbone: Show validation errors for each model in a collection on VIEW
- → OctoberCMS plugin show all the validations at once
Ad