Search code examples
octobercmsoctobercms-backend

Multiple Trigger on single Field in fields.yaml (OctoberCMS)


I'm currently trying to add a trigger to a form with multiple trigger on single field.

In my case when select intetnal it triggers contenttype and than it shows video or article based on selection. And after doing all things when I will select external from link it will not trigger to close contenttype

I am trying but not working :

   link:
        label: 'Internal Or External Link'
        options:
            internal: Internal
            external: External
        span: full
        default: internal
        required: 1
        type: dropdown
        comment: 'Select Link Type'
    external_link:
        label: 'External Link'
        span: full
        trigger:
            action: show
            field: link
            condition: 'value[external]'
        type: text
        comment: 'Enter External Link'
    content_type:
        label: 'Content Type'
        options:
            video: Video
            article: Article
        span: full
        trigger:
            action: show
            field: link
            condition: 'value[internal]'
        type: dropdown
        comment: 'Select Content Type'
    videolink:
        label: 'Video Link'
        span: full
        trigger:
            action: show
            field: content_type
            condition: 'value[video]'
        type: text
        comment: 'Enter Video Link'
    article_content:
        label: 'Article Content'
        size: large
        span: full
        trigger:
            action: show
            field: content_type
            condition: 'value[article]'
        type: richeditor
        comment: 'Add Article Content'

Solution

  • Hmm, you can do it but we need to make sure content_type get empty on hide

    so, we can do this

    external_link:
        label: 'External Link'
        span: full
        trigger:
            action: hide
            field: link
            condition: 'value[internal]'
        type: text
        comment: 'Enter External Link'
    content_type:
        label: 'Content Type'
        emptyOption: -- select a status --
        options:
            video: Video
            article: Article
        span: full
        trigger:
            action: hide|empty
            field: link
            condition: 'value[external]'
        type: dropdown
        comment: 'Select Content Type'
    

    we can use multiple actions to get our job done. and yes we also need to add emptyOption for content_type to make it empty.

    so when link value is external then it will hide and empty field content_type so in order to that reaction videolink OR article_content can not get its value as content_type will be empty so they also hide with that.

    For the sake of simplicity I am putting diff images so you get better idea what I have changed :)

    enter image description here

    <= left old one right => new one

    if any doubt please comment.