2016-09-16 60 views
1

form_image如何在OctoberCMS中設置中繼器內部區域的驗證?

我試過下面的代碼,但它不適合我。

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 

型號

public $rules = [ 
    'repetor_name' => 'required', 
    'required_text' =>'required' 
    ]; 

請與我分享你的知識,如果任何人有這方面的解決方案。由於

回答

1

可以在模型文件中添加以下代碼

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'; 
     } 
相關問題