verbb / formie

The most user-friendly forms plugin for Craft CMS.
Other
93 stars 69 forks source link

Dropdown fields withing repeater field aren't retaining values when pressing save on multi page forms #1822

Closed DenyEs closed 2 months ago

DenyEs commented 2 months ago

Describe the bug

Our dropdown fields won't retain values when in repeater fields after hitting save, even when presing save an continue, they're saved but going back to the previous page renders them empty.

This works fine on Formie 2.1.9 but breaks on 2.1.10

Steps to reproduce

  1. Create a multi page form
  2. Add a repeater field
  3. Add dropdwon field within repeater field
  4. Save on the first page with dropdown value populated

Form settings

Craft CMS version

4.8.9

Plugin version

2.1.10

Multi-site?

No

Additional context

This works fine on Formie 2.1.9 but breaks on 2.1.10

engram-design commented 2 months ago

I can't seem to replicate this, and the fix in 2.1.10 was applied to fix this exact scenario. Anything custom you're doing on your end with template overrides or anything?

DenyEs commented 2 months ago

Seems oddt then, as soon as I downgrade to 2.1.9, it works fine for me. I do have custom bulk options I am loading on the project we discovered this issue on, but I managed to replicate it on our sandbox as well. I've attached the screen recording as well where you can see that as soon as I save, the chosen option get's wiped. Sandbox have no custom templates or code relating to Formie at all.

https://github.com/verbb/formie/assets/18517642/dbad373e-98d5-476a-ace7-19557f415e9b

engram-design commented 2 months ago

That is odd. What about adding other fields, like a Single-Line Text?

For reference, a video from me: https://share.cleanshot.com/bv4QzDTf

Will try to see how to replicate what you're seeing.

engram-design commented 2 months ago

If you're up for debugging, try adding {{ dump(block }} at this line to see what that produces.

DenyEs commented 2 months ago

It does the same thing for me with other fields, including Single-Line Text.

dumping block on the file you references return a template error saying the block doesn't exist.

I tried making all fields not-required to see if that had something to do with it, but the results are the same, dropdown and single-line text values are being dropped

DenyEs commented 2 months ago

However, when I look at the incomplete submission in the CMS, those values are present, so it remember how many repeater fields I've added and it renders that amount, but it's not populating values

engram-design commented 2 months ago

Sorry, that should be {{ dump(block ?? []) }} and it should show a verbb\formie\elements\NestedFieldRow object

DenyEs commented 2 months ago

Yes, that's correct, it does show the NestedFieldRow object

array:1 [▼0 =>verbb\formie\elements\NestedFieldRow {[#1890 ▼](https://sandbox-c4.test/contact-us#sf-dump-1694073332-ref21890)
    -_events: []
    -_eventWildcards: []
    -_behaviors: array:1 [▶]
    -_errors: null
    -_validators: null
    -_scenario: "default"
    #revisionCreatorId: null
    #revisionNotes: null
    -_canonicalId: null
    -_canonical: null
    -_canonicalAnySite: null
    -_canonicalUid: null
    -_outdatedAttributes: null
    -_modifiedAttributes: null
    -_outdatedFields: null
    -_modifiedFields: null
    -_initialized: true
    -_fieldsByHandle: []
    -_fieldParamNamePrefix: null
    -_normalizedFieldValues: null
    -_allDirty: false
    -_dirtyAttributes: []
    -_savedTitle: null
    -_dirtyFields: []
    -_nextElement: verbb\formie\elements\NestedFieldRow {[#1895 ▶](https://sandbox-c4.test/contact-us#sf-dump-1694073332-ref21895)}
    -_prevElement: verbb\formie\elements\NestedFieldRow {[#1891 ▶](https://sandbox-c4.test/contact-us#sf-dump-1694073332-ref21891)}
    -_parentId: null
    -_parent: null
    -_hasNewParent: null
    -_prevSibling: null
    -_nextSibling: null
    -_eagerLoadedElements: []
    -_eagerLoadedElementCounts: []
    -_currentRevision: null
    -_enabledForSite: true
    -_uiLabel: null
    -_uiLabelPath: []
    -_isFresh: null
    +id: 2086
    +tempId: null
    +draftId: null
    +revisionId: null
    +isProvisionalDraft: false
    +uid: "cb5194e7-cca6-4438-a446-dc87209e5a41"
    +siteSettingsId: 2086
    +fieldLayoutId: 86
    +structureId: null
    +contentId: 5
    +enabled: true
    +archived: false
    +siteId: 1
    +title: null
    +slug: null
    +uri: null
    +dateCreated: DateTime @1712925117 {#1896 ▶}
    +dateUpdated: DateTime @1712925117 {#1897 ▶}
    +dateLastMerged: null
    +dateDeleted: null
    +root: null
    +lft: null
    +rgt: null
    +level: null
    +searchScore: null
    +trashed: false
    +awaitingFieldValues: false
    +propagating: false
    +validatingRelatedElement: false
    +propagateAll: false
    +newSiteIds: []
    +isNewForSite: false
    +resaving: false
    +duplicateOf: null
    +firstSave: false
    +mergingCanonicalChanges: false
    +updatingFromDerivative: false
    +previewing: false
    +hardDelete: false
    +fieldId: 134
    +ownerId: 2083
    +sortOrder: 2
    +dirty: false
    +collapsed: false
    +deletedWithOwner: false
    -_owner: null
    -_fields: null}
]
DenyEs commented 2 months ago

Here's screenshots from both CMS and Front-End

Screenshot 2024-04-12 at 13 33 49 Screenshot 2024-04-12 at 13 33 42
engram-design commented 2 months ago

Thanks for confirming all that. Could you test removing value: field.getFieldValue(block ?? value), here?

DenyEs commented 2 months ago

Of course, that seems to have did the trick, removing that line does populate values and I can see them on the front-end as well as back-end. Tested with dropdown field as well as single-line text.

engram-design commented 2 months ago

Thanks for confirming! Will investigate further (this was a recent fix for another issue on populating fields)

DenyEs commented 2 months ago

No problem at all Josh, let me know if you'll need anything else, I am happy to help :)

We'll stay on 2.1.9 for now on production site as that line of code isn't present on that version and it works fine.

Cheers

engram-design commented 2 months ago

Fixed for the next release. To get this early, run composer require verbb/formie:"dev-craft-4 as 2.1.10".

engram-design commented 2 months ago

Fixed in 2.1.11