-1

i did this in plugin.php boot function to addfield in repeater field

WartaRutin::extendFormFields(function($form){ 

        if(!$model instanceof Kebaktian) return;

        if(!$form->model->kebum) return;

        if(!$form->isNested) return;                       

            $form->addFields([

              'addition' => [
                     'label' => 'addition label',
                     'span' => 'storm',
                     'cssClass' => 'col-sm-4',
                     'type' => 'text']

        ]);      

});

the result produce additional field perfectly.. the problem is after data is saved, it doesn`t show in the form but data exist in database,,

how should i solve this..

Isral Bustami
  • 137
  • 13
  • 1
    i guess you need to take inpit from user in some structured way store in database then you need to update/append that `structured data` using this https://octobercms.com/docs/backend/forms#extend-form-fields – Hardik Satasiya Jul 19 '18 at 14:40
  • 1
    great reference.. so in my condition.. `$form->addFields()` become `$form->kebum->addFields()` am i right? – Isral Bustami Jul 19 '18 at 15:16
  • 1
    this method is adding new fields or remove the existing and then add new fields – Isral Bustami Jul 19 '18 at 15:18
  • 1
    i am guessing that we dont need to worries about database fields name.. since field name inside repeater field will be save as string array for repeater field name in database.. – Isral Bustami Jul 19 '18 at 15:28
  • hmm need to check that – Hardik Satasiya Jul 23 '18 at 07:53
  • actually i just checked all models.. it happens for all repeater field that i create.. i guess since i add backend users id in all model.. do we need to extend query for the repeater field.. – Isral Bustami Jul 23 '18 at 07:59

1 Answers1

1

yes, you are correct we dont need to worry about database fields.

as repeater field is build of json so in database its json and when you fetch from database its array

just take structured input from user then use : extend-form-fields octobercms.com/docs/backend/forms#extend-form-fields

now you can add and remove fields from the repeater as user needed.

if any doubts please comment

Hardik Satasiya
  • 9,547
  • 3
  • 22
  • 40