This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

ims_pulse
ims_pulse

Hi. Am getting this error when I try to use a repeater field from the onset. I don't know where I am going wrong. If someone can please help? It works fine if I ignore the repeater, save the rest of the fields and then click the entry in the column and use the repeater field then. Here is my code:

For form with repeater

===================================
Form Field Definitions
===================================
fields: 
  coc:
    label: COC Requested? 
    disabled: false
    type: checkbox
    span: auto
  coa:
    label: COA Requested?
    disabled: false
    type: checkbox
    span: auto
  quotes@update:
    label: Quote No
    type: relation
    select: id
    disabled: true
  createdby:
    label: Created By
    disabled: true
    type: relation
    select: concat(first_name, ' ', last_name)
    span: auto
  updatedby:
    label: Updated By
    disabled: true
    type: relation
    select: concat(first_name, ' ', last_name)
    span: auto
  items:
    label: Items 
    type: repeater
    form:
      fields: 
        description:
          label: Pipe Description On Quote
          type: dropdown
          emptyOption: -- Select Item -- 

And For Model:

public function getDescriptionOptions()
{ 
   return Quoteitems::where('quote_id', '=', $this->quotes->id)->lists('description');
 }

The function getDescriptionOptions will work fine if I have saved my entries without the repeater field and then go back and use the repeater field after saving it. I know that for some reason, it's seeing my QuoteItems as null, but I don't know how to make it work. Please can someone point me in the right direction. Thank you!

Last updated

mjauvin
mjauvin

Can you show your quotes relation?

Also, try to properly format the code in your posts by surrounding it with "```" (three back-quotes to open and 3 more to close) and properly ident it (like I did in your initial post), otherwise it's unreadable.

mjauvin
mjauvin

I see the problem now, your getDescriptionOptions() method will get called first when the form is initialized, but the quotes propery has no value at this point (no selection).

So you need to add validation code like below:

public function getDescriptionOptions()
{
   if (!$this->quotes) {
      return [];
   }
   return Quoteitems::where('quote_id', '=', $this->quotes->id)->lists('description');
 }

And add dependsOn: quotes to your items field definition

ims_pulse
ims_pulse

Thanks a lot. It solved the issue of the error.

1-4 of 4

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.