spicywebau / craft-neo

A Matrix-like field type for Craft CMS that uses existing fields
Other
402 stars 63 forks source link

NEO field validation fails in slideout view #814

Closed davola closed 10 months ago

davola commented 10 months ago

Bug Description

When editing some entry content over a slideout window, the NEO field validation fails when trying to save. When making the same edit on the NEO field, but over a full window (editing the entry on the main window) it succeeds.

Steps to reproduce

  1. edit a given entry that has another entry reference via an entry field.
  2. doble ckick on the entry so it opens a slideout with the content
  3. Edit some content on the NEO filed of the opened slideout
  4. When clicking save on the slideout, saving fails with the Couldn’t save entry. entry.
  5. Debug window has this detailed error:

    SLIDEOUT SAVE REQUEST PAYLOAD

    mjchswfwhq[elementId]: 319504
    mjchswfwhq[siteId]: 1
    mjchswfwhq[title]: Store Locations
    mjchswfwhq[fields][blocks][new0][fields][columnTitle]: New Col
    mjchswfwhq[fields][blocks][new1][fields][sectionTitle]: New Section
    mjchswfwhq[fields][blocks][new1][fields][sectionItems]: 
    mjchswfwhq[fields][blocks][new1][fields][sectionItems][sortOrder][]: new1
    mjchswfwhq[fields][blocks][new1][fields][sectionItems][blocks][new1][type]: itemRow
    mjchswfwhq[fields][blocks][new1][fields][sectionItems][blocks][new1][enabled]: 1
    mjchswfwhq[fields][blocks][new1][fields][sectionItems][blocks][new1][fields][itemText]: New Row 1
    mjchswfwhq[fields][blocks][new1][fields][sectionItems][blocks][new1][fields][itemLink]: 
    mjchswfwhq[fields][blocks][new1][fields][sectionItems][sortOrder][]: new2
    mjchswfwhq[fields][blocks][new1][fields][sectionItems][blocks][new2][type]: itemRow
    mjchswfwhq[fields][blocks][new1][fields][sectionItems][blocks][new2][enabled]: 1
    mjchswfwhq[fields][blocks][new1][fields][sectionItems][blocks][new2][fields][itemText]: New Row 2
    mjchswfwhq[fields][blocks][new1][fields][sectionItems][blocks][new2][fields][itemLink]: 
    mjchswfwhq[action]: elements/apply-draft
    mjchswfwhq[slug]: store-locations
    mjchswfwhq[authorId]: 
    mjchswfwhq[authorId]: 5
    mjchswfwhq[enabledForSite][1]: 1
    mjchswfwhq[notes]: 
    mjchswfwhq[draftId]: 6843
    mjchswfwhq[provisional]: 1

    SLIDEOUT REQUEST ERROR RESPONSE

    {
    "modelName": "element",
    "element": {
        "sectionId": 33,
        "postDate": "2023-10-02T12:28:00-05:00",
        "expiryDate": null,
        "deletedWithEntryType": false,
        "_authorId": 5,
        "id": 325618,
        "tempId": null,
        "draftId": 6843,
        "revisionId": null,
        "isProvisionalDraft": true,
        "uid": "9d0fa65e-b924-4082-8505-eb82401a7a08",
        "siteSettingsId": 471867,
        "fieldLayoutId": null,
        "contentId": 198755,
        "enabled": true,
        "archived": false,
        "siteId": 1,
        "title": "Store Locations",
        "slug": "store-locations",
        "uri": null,
        "dateCreated": "2023-11-21T15:26:10-06:00",
        "dateUpdated": "2023-11-21T15:26:33-06:00",
        "dateLastMerged": null,
        "dateDeleted": null,
        "trashed": false,
        "isNewForSite": false,
        "canonicalId": 319504,
        "isDraft": true,
        "isRevision": false,
        "isUnpublishedDraft": false,
        "ref": "tableLists/store-locations",
        "status": "live",
        "structureId": null,
        "url": null,
        "authorId": 5,
        "typeId": 34
    },
    "errors": {
        "tableColumns[3].sectionItems": [
            "*Section Items* should contain at least 1 block."
        ]
    },
    "errorSummary": "<div class=\"error-summary\" tabindex=\"-1\"><div><span class=\"notification-icon\" data-icon=\"alert\" aria-label=\"error\" role=\"img\"></span><h2>Found 1 error</h2></div><ul class=\"errors\"><li><a href=\"https://craft-stage.metronet.com/admin?site=residential#\" data-field-error-key=\"tableColumns[3].sectionItems\"><em>Section Items</em> should contain at least 1 block.</a></li></ul></div>",
    "message": "Couldn’t save entry."
    }

    image

Expected behaviour

The slideout SAVE action should succeed the same way it succeds on a full edit windows.

Posible Error

"tableColumns[3].sectionItems": [
    "*Section Items* should contain at least 1 block."
]

The error claims that the tableColumns[3].sectionItems should have values on it - but the error is that we have only 2 table columns - tableColumns[0] and tableColumns[1] - so I believe the count on the slideouts fails somehow.

FYI: sectionItems is a required field, therefor that's why it say at least 1 block needed.

Neo version

NEO 3.9.7

Craft CMS version

Craft Pro 4.5.9

What is the affected Neo field's propagation method?

Save blocks to all sites the owner element is saved in

Does this issue involve templating, and if so, is eager-loading used?

This is not a templating issue

ttempleton commented 10 months ago

I'm unable to reproduce this - if possible, could you please send in your composer.json/lock files and database backup to plugins@spicyweb.com.au and let us know which entry this is happening with, and we'll have a look.

davola commented 10 months ago

Hey @ttempleton - while I can't give you the database copy I can tell you the field scafolding we have in place (its a bit tricky/complex)

tableList (entry type)

sectionItems field is detected as empty and fails validation as it has at least 1 required. The real problem is that we have only 2 tableColumns (the top level NEO field) added but this is detecting 3 by error.

Here sample top level NEO field tableColumn image

and child level NEO field columnSection image

Remember, this works properly on a full entry edit window. This only fails when editing on a slide-out window.

the plugins we have instaled are as follows:

"require": {
        "born05/craft-assetusage": "3.2.0",
        "craftcms/aws-s3": "2.0.3",
        "craftcms/cms": "4.5.9",
        "craftcms/feed-me": "5.2.0",
        "craftcms/google-cloud": "2.0.0",
        "craftcms/redactor": "3.0.4",
        "mmikkel/incognito-field": "1.3.0",
        "nystudio107/craft-seomatic": "4.0.33",
        "percipioglobal/craft-colour-swatches": "4.3.0",
        "spicyweb/craft-neo": "3.9.7",
        "verbb/field-manager": "3.0.7",
        "verbb/icon-picker": "2.0.14",
        "verbb/smith": "2.0.0",
        "verbb/super-table": "3.0.12",
        "vlucas/phpdotenv": "^3.4.0",
        "wrav/oembed": "2.3.0",
        "yiisoft/yii2-redis": "~2.0.0"
    },
    "require-dev": {
        "phpunit/phpunit": "^9",
        "yiisoft/yii2-shell": "^2.0.3"
    },

Hope this helps!

ttempleton commented 10 months ago

Thanks for that - I was able to reproduce with that information. It turned out to specifically affect new blocks, and it's fixed now in Neo 3.9.9.