Content picker: Remove multi-node content picker entries by UDI to account for index not aligning with stored values#20950
Merged
leekelleher merged 2 commits intov13/devfrom Dec 1, 2025
Conversation
…not aligning with stored values.
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request addresses an issue where removing items from the multi-node content picker fails when a previously picked item has been deleted, as the array index no longer reliably corresponds to the correct item. The fix changes the removal logic from index-based to identifier-based (UDI/ID) lookup.
- Refactored the
removefunction to accept and search by identifier (UDI or ID) instead of array index - Updated the HTML template to pass
node.udito the remove function instead of$index - Added null-check logic to handle cases where the identifier is not found
- Modified behavior to set
model.valuetonullwhen removing the last item (aligning withclear()behavior)
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Umbraco.Web.UI.Client/src/views/propertyeditors/contentpicker/contentpicker.controller.js | Refactored remove function from index-based to identifier-based removal with indexOf lookup and null-check handling |
| src/Umbraco.Web.UI.Client/src/views/propertyeditors/contentpicker/contentpicker.html | Updated remove callback to pass node.udi instead of $index |
| src/Umbraco.Web.UI.Client/test/unit/app/propertyeditors/content-picker-controller.spec.js | Updated test to pass identifier value (1231) instead of array index (1) to the remove function |
Comments suppressed due to low confidence (1)
src/Umbraco.Web.UI.Client/test/unit/app/propertyeditors/content-picker-controller.spec.js:88
- The test coverage for the updated
removefunction is incomplete. Consider adding tests for:
- Removing a non-existent item (should handle gracefully when the UDI/ID is not found)
- Removing the last remaining item (should set
model.valuetonull) - Attempting to remove when
allowRemoveis false
These edge cases are now important since the removal logic has changed from index-based to identifier-based lookup.
it("Removing an item should update renderModel, ids and model.value", function(){
scope.remove(1231);
scope.$apply();
expect(scope.renderModel.length).toBe(2);
expect(scope.model.value).toBe("1233,23121");
});
src/Umbraco.Web.UI.Client/src/views/propertyeditors/contentpicker/contentpicker.controller.js
Outdated
Show resolved
Hide resolved
src/Umbraco.Web.UI.Client/src/views/propertyeditors/contentpicker/contentpicker.html
Outdated
Show resolved
Hide resolved
leekelleher
approved these changes
Dec 1, 2025
Member
leekelleher
left a comment
There was a problem hiding this comment.
Tested out, works as described. 🚀
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prerequisites
Fixes: #20943
Description
As noted on the linked issue, if a picked item has been deleted the index can no longer be relied upon to be correct as an indicator of the item to be removed. This updates to use the UDI of the item instead.
Testing
See reproduction steps in linked issue.