Repository: collective/collective.cover (language: python)

Issue:
The clear filter button in the content chooser doesn't work
When we have filtered contents, and we click on the "X" button to clear the filter, the contents tree continues listing the items of the previous filter, the amount of items found:

![chrome-capture-2023-2-22](https://user-images.githubusercontent.com/3297795/227028557-71584161-911c-4923-8602-0513de40d0d3.gif)

In Javascript console we see the error:

```javascript
cover-8201835.js:1
Uncaught ReferenceError: portal_url is not defined
    at HTMLAnchorElement.<anonymous> (cover-8201835.js:1:14550)
    at HTMLDocument.dispatch (jquery.min.js:3:12444)
    at p.dispatch (plone-logged-in-compiled.js:8311:19)
    at r.handle (jquery.min.js:3:9173)
```


Discussion / hints:

Fix patch:
diff --git a/CHANGES.rst b/CHANGES.rst
index 15a25b0b..57f74645 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -6,6 +6,9 @@ There's a frood who really knows where his towel is.
 3.0.0 (unreleased)
 ^^^^^^^^^^^^^^^^^^
 
+- Fix error when clearing content chooser input (fixes `#942 <https://github.com/collective/collective.cover/issues/942>`_).
+  [wesleybl]
+
 - Improve content chooser search input layout.
   [wesleybl]
 
diff --git a/webpack/app/js/contentchooser.js b/webpack/app/js/contentchooser.js
index 9c105315..1a885503 100644
--- a/webpack/app/js/contentchooser.js
+++ b/webpack/app/js/contentchooser.js
@@ -231,7 +231,7 @@ export default class ContentChooser {
     );
     this.filterOnKeyUp();
     $('#contentchooser-content-search #recent .item-list').on('scroll', this.onRecentScroll.bind(this));
-    $(document).on('click', '#recent .contentchooser-clear', function(e) {
+    $(document).on('click', '#recent .contentchooser-clear', e => {
       $(e.currentTarget).prev().children('input').val('');
       let url = $('#contentchooser-content-search-button').attr('data-url');
       this.ajaxSearchRequest.push($.ajax({
@@ -244,9 +244,9 @@ export default class ContentChooser {
       }));
       return false;
     });
-    $(document).on('click', '#content-trees .contentchooser-clear', function(e) {
+    $(document).on('click', '#content-trees .contentchooser-clear', e => {
       $(e.currentTarget).prev().children('input').val('');
-      this.getFolderContents(portal_url, '@@jsonbytype');
+      this.getFolderContents(this.portal_url, '@@jsonbytype');
       return false;
     });
     $('#contentchooser-content-search-button').click(function(e) {


Test patch:
diff --git a/src/collective/cover/tests/test_contentchooser.robot b/src/collective/cover/tests/test_contentchooser.robot
index f20f820e..aa299539 100644
--- a/src/collective/cover/tests/test_contentchooser.robot
+++ b/src/collective/cover/tests/test_contentchooser.robot
@@ -10,6 +10,7 @@ Suite Teardown  Close all browsers
 
 ${basic_tile_location}  'collective.cover.basic'
 ${file_selector}  .ui-draggable .contenttype-file
+${document_selector}  a[title="This document was created for testing purposes : /my-document"]
 ${contentchooser_search_selector}  FIXME
 ${contentchooser_search_clear}  a.contentchooser-clear
 ${contentchooser_close}  div.close
@@ -38,10 +39,11 @@ Test Content Chooser
 
     # make a search on Recent Items
     Click Element  link=Recent Items
-    Input Text  css=#recent input  folder
-    # FIXME: we have no result counter in here
-    #Wait Until Page Contains  1 Results
+    Input Text  css=#recent input  My file
+    Wait Until Page Contains  1 Results
     Click Element  css=#recent ${contentchooser_search_clear}
+    Page Should Not Contain  1 Results
+    Page Should Contain Element  css=${document_selector}
 
     Click Element  link=Content Tree
     Wait Until Page Contains  Plone site
@@ -52,6 +54,8 @@ Test Content Chooser
 
     # navigate the tree
     Click Element  css=#content-trees ${contentchooser_search_clear}
+    Page Should Not Contain  1 Results
+    Page Should Contain Element  css=${document_selector}
     Input Text  css=#content-trees input  file
     Wait Until Page Contains  1 Results
     Page Should Contain Element  css=${file_selector}