Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Umbraco Forms 8.9+ upgrade issues with duplicates in a repeater are not allowed. #944

Closed
aochmann opened this issue Jan 4, 2023 · 2 comments

Comments

@aochmann
Copy link

aochmann commented Jan 4, 2023

Hi all,
I am writing to you about some Umbraco Forms issue that we are having with some old existing forms. The issue is related to duplicated keys: "Duplicates in a repeater are not allowed". Let me explain the full path of the issue.

We are running on Umbraco Forms 8.8.0 and we are having some existing forms. All is good on this version. The issue begins after upgrading Umbraco Forms to any newer version. The issue is related to existing forms when trying to view them in the backoffice Forms designer tab. It gives errors in the console and the output of it is that the selected form does not display.

Here is some of the error message:

Error: [ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: fieldset in page. fieldSets track by fieldset.id, Duplicate key: 00000000-0000-0000-0000-000000000000

image

I investigated that a little and have some workaround - but it's something that for the long term we don't want to use as after the next Umbraco Forms upgrade it will be overridden again.

The fix is to remove the track by fieldset.id from this file umb-forms-designer-new.html

<div class="umb-forms__fieldset sortable" ng-repeat="fieldset in page.fieldSets" ng-class="{'-active':fieldset.state =='active'}" ng-click="setActive(fieldset)" data-umb="fieldset_{{$parent.$index}}_{{$index}}">

After that, it starts to work - displaying the forms fields. I did check and this was changed after merging some work for this issue: #647

And here question, what is your recommended approach to it? Is there a recommended way that doesn't have to change Umbraco files? Is this issue related to existing forms only?

Cheers,
Adrian

@AndyButland
Copy link

Would you mind sharing one of your form definitions that shows this issue please @aochmann? You can email it to abl AT umbraco DOT dk if you prefer to not share it publicly here.

This will either be the JSON file on disk, or, if you are storing form definitions in the database, the contents of the Definition field of the UFForms table for the form in question.

I'd like to check it locally on the latest version of Forms and see if I can replicate the issue and review your suggested fix.

I suspect another approach to fix would be to manipulate the definitions of your forms to provide non-empty GUID IDs for the field set IDs. If you only have a few, that could be another option to take.

@AndyButland
Copy link

Thanks for sending over, I can replicate. I can confirm the workaround will fix it, which is quite straightforward for this one form, but how big a task it would be is tricky to say without knowing how many forms you have. I'll detail it anyway.

The crux of the issue is that the fieldsets on these older forms have empty GUIDs for IDs, and the back-office UI at this time (and looks like as of 8.7) has this expectation that they be unique.

So you could just manipulate the files to fix this up. For any that have more than one field set, like this one, replace:

"fieldSets": [
  {
    ...
    "id": "00000000-0000-0000-0000-000000000000",
    ...
  },
  {
    ...
    "id": "00000000-0000-0000-0000-000000000000",
    ...
  },
  {
    ...
    "id": "00000000-0000-0000-0000-000000000000",
    ...
  },

With e.g.:

"fieldSets": [
  {
    ...
    "id": "00000000-0000-0000-0000-000000000001",
    ...
  },
  {
    ...
    "id": "00000000-0000-0000-0000-000000000002",
    ...
  },
  {
    ...
    "id": "00000000-0000-0000-0000-000000000003",
    ...
  },

Then save the file, restart the website, and they should be fine to edit again.

I don't think we can remove this track-by line to fix it, as that'll cause issue with the "copy form group" function that's been added in an earlier version.

We can though add some code to handle this legacy state, where if we find fields sets with empty GUIDs, we initialise them to unique, non-empty values when the form is being loaded in the back-office. It then loads OK. We'll include that in the next patch release for Forms 8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants