getkirby / kirby

Kirby's core application folder
https://getkirby.com
Other
1.32k stars 168 forks source link

Clone row on duplicate In structure field #6073

Closed georgobermayr closed 10 months ago

georgobermayr commented 11 months ago

Description

I have a very strange issue in a custom field implementation: I moved the actual editing of the blocks field into a drawer. This works fine. However, if have an issue with structure fields inside of a block, when using my custom field:

With the original Kirby implementation everything works fine. But for some reason it occurs with my custom field.

Expected behavior
The content of the duplicated structure should only be changed in the duplicated row and not also in the original row.

Sugessted fix After a lot of digging I didn't find the issue witting my field implementation. However I found a way to fix it within Kirby. In the Structure field component (https://github.com/getkirby/kirby/blob/main/panel/src/components/Forms/Field/StructureField.vue#L458) instead of doing:

case "duplicate":
    this.add({
        ...row,
        _id: this.$helper.uuid()
    });
    break;

doing this:

case "duplicate":
    this.add({
        ...this.$helper.clone(row),
        _id: this.$helper.uuid()
    });
    break;

is fixing the issue with row duplication/editing in my custom field. I don't know what the real root cause for the issue in my field is, but this seems to be a plausible fix for me. The same is already done for block duplication, so would it be possible, to do the cloning for structures as well?

Your setup

Kirby Version 4.0.0

bastianallgeier commented 10 months ago

Will be fixed in 4.1