leekelleher / umbraco-contentment

Contentment for Umbraco - a state of happiness and satisfaction
https://marketplace.umbraco.com/package/umbraco.community.contentment
Mozilla Public License 2.0
157 stars 72 forks source link

Selection of items not working correctly after saving entity #109

Closed bjarnef closed 3 years ago

bjarnef commented 3 years ago

What is the current behaviour?

In general the selection using item picker works as expected. However we have noticed a strange behaviour when creating a new node, clicking save & publish and then using the item picker. When selecting e.g. 3 items after the Umbraco content/entity has been created and clicking submit if only shows 1 single item and after clicking save & publish again no items are saved.

It also doesn't seem to be an issue with the selection directly when creating a new content node and using the item picker before the node is saved.

What is the expected behaviour?

The selection of the item picker should work in same way after creating the entity as on existing nodes/entities.

Please tell us about your set-up:

In this scenario I get a console error:

image

Test notes

I guess it is an issue somewhere where it is trying to push an item to $scope.model.value, but where this is null, undefined or maybe just an empty string.

bjarnef commented 3 years ago

It seems to be related to this:

image

And this part in the code: https://github.com/leekelleher/umbraco-contentment/blob/951ec6416550d5c1ded6b78c1017c23f2e97fcb1/src/Umbraco.Community.Contentment/DataEditors/ItemPicker/item-picker.js#L132

After re-refreshing page model.value is an empty array, but apparently an empty string right after document has been saved. @leekelleher could you add some additional check to ensure model.value is an array?

E.g.

$scope.model.value = $scope.model.value || [];

It fails if trying to push an object to a string:

image

But if with the code above if $scope.model.value is null, undefined or an empty string it will return an empty array.

image

leekelleher commented 3 years ago

@bjarnef Just to let you know that I can reproduce the issue. Quite odd that the page save sets the value as an empty string. I'm looking into resolutions. 👍

leekelleher commented 3 years ago

@bjarnef I've put a fix in commit 7929b2d2725638a86b4dc7855bac6063a9eeec4c, but that's currently in the v2.0 branch, (as that's where my current focus is at), but if I get time next week, then I'll look as doing a v1.4.3 patch release with other recent fixes.

bjarnef commented 3 years ago

@leekelleher okay, maybe a datatype storing JSON by default return an empty string, when the entity is created? Anyway would be great to backport to v1.4.3 as well 🤓👍