Cms: Replicator content dissapears from collection entity when replicator set has a link with condition

Created on 10 Feb 2021  路  11Comments  路  Source: statamic/cms

Bug Description

Content of replicator disappears when you create a condition to hide a link field when a entity field is not null.
The same rule works fine on a text field.

How to Reproduce

  • create fieldset
  • create replicator field
  • create replicator set
  • create fields (must contain entity field) except for link field
  • save the fieldset
  • create a bard field inside a collection entity that contains the above fieldset as a set of it's own
  • create a bunch of content inside a entities bard with the current fieldset and save the entity
  • go back to the fieldset
  • open replicator
  • add link field
  • add condition to the link field to be hidden when entity is not null
  • save fieldset
  • return to the entity you have content entered with this fieldset in a bard
  • find that the content is empty

Extra Detail

https://user-images.githubusercontent.com/60649057/107571992-f3668180-6beb-11eb-8c4a-8b1b4e6d042b.mp4

Environment

Statamic version: 3.0.42 Pro
PHP version: 7.4.9
Fresh install from statamic/statamic

bug

Most helpful comment

I agree that the control panel shouldn't break like this, just for using a wrong (or less suitable) validator. It should only affect the validation.

All 11 comments

Do you get any console errors?

No console errors.

Here is the headers and the payload on save:

###General
Request URL: http://laravel.local:8080/cp/fields/fieldsets/cards
Request Method: PATCH
Status Code: 204 No Content
Remote Address: 127.0.0.1:8080
Referrer Policy: strict-origin-when-cross-origin

###Response Headers
Cache-Control: no-cache, private
Connection: keep-alive
Date: Wed, 10 Feb 2021 23:04:05 GMT
Server: nginx/1.19.2
Set-Cookie: XSRF-TOKEN=****; expires=Thu, 11-Feb-2021 01:04:05 GMT; Max-Age=7200; path=/; samesite=lax
Set-Cookie: festival_of_tolerance_session=****; expires=Thu, 11-Feb-2021 01:04:05 GMT; Max-Age=7200; path=/; httponly; samesite=lax
X-Powered-By: PHP/7.4.11
X-Powered-By: Statamic

###Request Headers
Accept: application/json, text/plain, */*
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9
Cache-Control: no-cache
Connection: keep-alive
Content-Length: 1823
Content-Type: application/json;charset=UTF-8
Cookie: _ga=GA1.1.1794044943.1600172357; _ga_SW0WBPTDW3=GS1.1.1612992467.46.1.1612992828.0; XSRF-TOKEN=****; festival_of_tolerance_session=*****
Host: laravel.local:8080
Origin: http://laravel.local:8080
Pragma: no-cache
Referer: http://laravel.local:8080/cp/fields/fieldsets/cards/edit
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36
X-CSRF-TOKEN: *****
X-Requested-With: XMLHttpRequest
X-XSRF-TOKEN: *****

###Request Payload
{title: "Cards", handle: "cards", fields: [{handle: "cards", type: "inline",鈥]}
  fields: [{handle: "cards", type: "inline",鈥]
    0: {handle: "cards", type: "inline",鈥
      config: {collapse: false, sets: {cards: {display: "Cards",鈥}, display: "Cards", type: "replicator",鈥
        collapse: false
        display: "Cards"
        icon: "replicator"
        instructions: null
        listable: "hidden"
        localizable: true
        max_sets: null
        sets: {cards: {display: "Cards",鈥}
          cards: {display: "Cards",鈥
            display: "Cards"
            fields: [{handle: "program",鈥, {handle: "grid",鈥, {handle: "thumbnail",鈥, {handle: "description",鈥,鈥
              0: {handle: "program",鈥
                field: {max_items: 1, mode: "default", collections: ["programs", "pages"], display: "Content",鈥
                  collections: ["programs", "pages"]
                  display: "Content"
                  icon: "entries"
                  listable: "hidden"
                  max_items: 1
                  mode: "default"
                  type: "entries"
                  unless: {external_link: "not null"}
                  handle: "program"
              1: {handle: "grid",鈥
              2: {handle: "thumbnail",鈥
              3: {handle: "description",鈥
              4: {handle: "cta",鈥
              5: {handle: "external_link",鈥
                field: {display: "External Link", type: "link", icon: "link", listable: "hidden",鈥
                  display: "External Link"
                  icon: "link"
                  listable: "hidden"
                  type: "link"
                  unless: {program: "not null"}
                  handle: "external_link"
              6: {handle: "title",鈥
        type: "replicator"
        validate: []
        width: 100
      fieldtype: "replicator"
      handle: "cards"
      icon: "replicator"
      type: "inline"
      _id: 0
    handle: "cards"
    title: "Cards"

Does your issue sound like the same thing as #3153?

No this issue is something else entirely. There is a error output on the entity side however.
Was late yesterday and I didn't check the entry editor side just the rules side.

Screenshot from 2021-02-11 08-36-42

Would you mind sharing the replicator field from your blueprint file so we can attempt to replicate?

the fieldset yaml with the replicator;

title: Cards
fields:
  -
    handle: cards
    field:
      collapse: false
      sets:
        cards:
          display: Cards
          fields:
            -
              handle: program
              field:
                max_items: 1
                mode: default
                collections:
                  - programs
                  - pages
                display: Content
                type: entries
                icon: entries
                listable: hidden
                unless:
                  external_link: 'not null'
            -
              handle: grid
              field:
                options:
                  col-12: 1/1
                  col-6: 1/2
                  col-4: 1/3
                  col-3: 1/4
                multiple: false
                max_items: 3
                clearable: false
                searchable: false
                taggable: false
                push_tags: false
                cast_booleans: false
                display: Grid
                type: select
                icon: select
                listable: hidden
            -
              handle: thumbnail
              field:
                mode: grid
                container: assets
                restrict: false
                allow_uploads: true
                max_files: 1
                display: Thumbnail
                type: assets
                icon: assets
                instructions: '(optional) if left empty, the content display image will be used'
                listable: hidden
            -
              handle: description
              field:
                character_limit: '300'
                antlers: false
                display: Description
                type: textarea
                icon: textarea
                instructions: '(optional) if left empty the content 1st text field will be used'
                listable: hidden
            -
              handle: cta
              field:
                input_type: text
                antlers: false
                display: CTA
                type: text
                icon: text
                listable: hidden
            -
              handle: external_link
              field:
                display: 'External Link'
                type: link
                icon: link
                listable: hidden
                unless:
                  program: 'not null'
            -
              handle: title
              field:
                input_type: text
                antlers: false
                display: Title
                type: text
                icon: text
                listable: hidden
                unless:
                  external_link: 'equals null'
      display: Cards
      type: replicator
      icon: replicator
      localizable: true
      listable: hidden

Thanks! I can confirm, the same thing happens to me, the replicator set doesn't show for me.

image

I would suggest using is empty wherever possible, unless you need to check against a literal null.

Your program entries field stores as an array in Vue (even when empty, by design), so is null is too strict of a check. Our is empty check will intelligently check for null, '', and [], which is more reliable in most cases, and fixes your specific issue here.

image

so disappearing content is a feature? And a "workaround" is an acceptable QA? Damn, I'd expect this from wordpress, and not from a payed software.

I agree that the control panel shouldn't break like this, just for using a wrong (or less suitable) validator. It should only affect the validation.

@radovanobal @arthurperton Ah, the JS was breaking more than just the condition. Good call on that, see above fix. Will be in the next tagged 3.0.* release 馃憤

That said, you'll still need to check for empty over a literal null though, if you want entries field condition to work as you'd expect here. Example:

unless:
  program: 'not empty'

Or without the double negative:

if:
  program: 'empty'
Was this page helpful?
0 / 5 - 0 ratings

Related issues

andrewying picture andrewying  路  4Comments

austenc picture austenc  路  3Comments

dakisan picture dakisan  路  4Comments

ReneWeCode picture ReneWeCode  路  3Comments

sandervanh picture sandervanh  路  4Comments