unfoldadmin / django-unfold

Modern Django admin theme for seamless interface development
https://unfoldadmin.com
MIT License
1.52k stars 150 forks source link

Search form not working. #584

Closed khaled5321 closed 1 month ago

khaled5321 commented 1 month ago

Hey there, I'm having trouble with the search bar on the model page when using my mobile. It's not working, but it works fine on my laptop (EDIT: it's not working at all now). I am downloading the package directly from Github.

I checked the server logs and saw that when I try to search, it sends "undefined" in the query parameter, like this: /admin/accounts/user/?=undefined

I also found an error in the browser console, I don't know if they are related, but I attached it just in case:

Uncaught TypeError: t.interceptClone is not a function
    at Vt (alpine.anchor.js:1:14274)
    at Object.Or [as plugin] (alpine.js:5:13299)
    at HTMLDocument.<anonymous> (alpine.anchor.js:1:15506)
    at q (alpine.js:5:3496)
    at Object.ur [as start] (alpine.js:5:4031)
    at alpine.js:5:35990
khaled5321 commented 1 month ago

I found the issue. It is coming from here

  const getQueryParams = (searchString) => {
    console.log(window.location.search)
    const queryParams = window.location.search
      .replace("?", "")
      .split("&")
      .map((param) => param.split("="))
      .reduce((values, [key, value]) => {
        if (key == "q") {
          values[key] = searchString;
        } else {
          values[key] = value;
        }

        return values;
      }, {});

    const result = Object.entries(queryParams)
      .map(([key, value]) => `${key}=${value}`)
      .join("&");

    return `?${result}`;
  };

window.location.search returns an empty string

lukasvinclav commented 1 month ago

I'm trying to replicate this issue on local but I'm not sure how to proceed. I opened admin page with search and other filters in mobile resolution but I don't see any errors in console. Do you some more information which can help me?

khaled5321 commented 1 month ago

What information can I provide to help you?

I installed Unfold from GitHub using pip install https://github.com/unfoldadmin/django-unfold/archive/main.zip and followed the installation and configuration instructions.

lukasvinclav commented 1 month ago

I need to be able to replicate the issue. On Firefox, in mobile resolution I don't have any console errors. Maybe you can tell which browser are you using? Which operating system? Are you able to replicate the issue only on physical mobile device or is it possible to have it on desktop as well?

khaled5321 commented 1 month ago

It also happens on desktop. I am using chrome and Windows 11. Also, the console error doesn't always show up, the main issue is that the search is not working at all.

lukasvinclav commented 1 month ago

Please create a new repository with the minimal example where I can see an error.

khaled5321 commented 1 month ago

Here is the repo link: https://github.com/khaled5321/test-unfold-bug

khaled5321 commented 1 month ago

The same issue is mentioned here: https://github.com/unfoldadmin/django-unfold/issues/556#issuecomment-2222375899

lukasvinclav commented 1 month ago

Would you mind to test main branch again? I merged two PRs addressing filter issues.

khaled5321 commented 1 month ago

I tested it. It is working now. Thank you!