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

nb17912
nb17912

Hi! In my current project I have a form with a repeater for filling content into components with different templates. Everything works fine as long as I ignore the templates. But what I want to do is to look on the chosen template with an trigger event inside the repeater so that some fields are only shown, if one specific template is chosen. But none of the fields inside the repeater will react to the trigger as expected... Can anyone understand my problem and give me a hint, how to solve this problem? Thanks!!

template:
        label: Choose template
        type: radio
        options:
          1: Template 1
          2: Template 2
          3: Template 3
        required: true
        tab: Tab1
content:
        label: content
        tab: Tab2
        type: repeater
        prompt: new content area
        form:
          fields:
            text:
              label: text block
              type: text
            videos:
              label: videos
              type: text
              trigger:
                action: show
                field: template
                condition: value[2]
aaron.humphreys
aaron.humphreys

I have just run into this issue myself. I know this is an old topic, but I have yet to find a proper resolution, so posting what I know here to help others thus far.

The issue displayed above is that the repeater cannot access the values from the parent form. To have this trigger work, you need to have it in the repeater. This is not an ideal solution, but a work around for the time being. So this would become

content:
    label: content
    tab: Tab2
    type: repeater
    prompt: new content area
    form:
      fields:
        template:
          label: Choose template
          type: radio
          options:
            1: Template 1
            2: Template 2
            3: Template 3
          required: true
        text:
          label: text block
          type: text
        videos:
          label: videos
          type: text
          trigger:
            action: show
            field: template
            condition: value[2]
Troiscent
Troiscent

Any update on this ? I have some fields in a repeater that need to be hidden depending on a field that is outside the repeater. It does not work actually.

aaron.humphreys
aaron.humphreys

Troiscent said:

Any update on this ? I have some fields in a repeater that need to be hidden depending on a field that is outside the repeater. It does not work actually.

While I have not tested this, you may be able to hook into the filterFields method in the Model.

public function filterFields($fields, $context = null)
{
    if ( $fields->triggerField == true ) {
        foreach ($fields->repeaterName as $item) {
            $item->fieldToHide->hidden = true;
        }
}

Where "triggerField" is the filed you are using as your trigger to show / hide fields and "repeaterName" is your repeating field. Given nb17912's original fields, this would mean

public function filterFields($fields, $context = null)
{
    if ( $fields->template == '2' ) {
        foreach ($fields->content as $item) {
            $item->videos->hidden = true;
        }
}

As I said, this is untested. Please let me know if this works.

1-4 of 4

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