You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
protected function fetchUsers()
{
return $this->fetch([
'model' => \App\Models\Users::class,
// Custom search to allow us to search full name
'query' => function ($model) {
$searchTerm = request()->input('q');
return $model->WhereRaw('CONCAT(`firstname`," ",`lastname`) LIKE "%'.$searchTerm.'%"');
},
'paginate' => 2, // <== just to highlight the problem
]);
}
What I expected to happen
The results list would show 2 records, and the link to loading more results if there is another results page
What happened
It didn't show the loading more results link, it only showed two results, even though there were more results on another page
What I've already tried to fix it
I noticed that in select2_from_ajax.blade.php the code for deciding to paginate looks like this:
paginate = data.next_page_url !== null;
But in morphTo_select_ajax.blade.php the code incorrectly uses:
paginate = data.current_page < data.last_page;
But because data.current_page returns 1 for the first page, not 0, the pagination decision will always fail if there's only two pages as the last_page index will be the same as the current_page index.
Here's the data parameter js console output from morphTo_select_ajax.blade.php@processResult#200 if there's only two pages of data to return:
Hello there! Thanks for opening your first issue on this repo!
Just a heads-up: Here at Backpack we use GitHub Issues only for tracking bugs. Talk about new features is also acceptable. This helps a lot in keeping our focus on improving Backpack. If you issue is not a bug/feature, please help us out by closing the issue yourself and posting in the appropriate medium (see below). If you're not sure where it fits, it's ok, a community member will probably reply to help you with that.
Long questions (I have done X and Y and it won't do Z wtf) - Stackoverflow, using the backpack-for-laravel tag;
Showing off something you've made, asking for opinion on Backpack/Laravel matters - Reddit;
Please keep in mind Backpack offers no official / paid support. Whatever help you receive here, on Gitter, Slack or Stackoverflow is thanks to our awesome awesome community members, who give up some of their time to help their peers. If you want to join our community, just start pitching in. We take pride in being a welcoming bunch.
Bug report
What I did
Created a CRUD::Field on an morphable relation, defining an ajax datasource for the results:
The fetch method is defined as:
What I expected to happen
The results list would show 2 records, and the link to loading more results if there is another results page
What happened
It didn't show the loading more results link, it only showed two results, even though there were more results on another page
What I've already tried to fix it
I noticed that in
select2_from_ajax.blade.php
the code for deciding to paginate looks like this:But in
morphTo_select_ajax.blade.php
the code incorrectly uses:But because
data.current_page
returns1
for the first page, not0
, the pagination decision will always fail if there's only two pages as thelast_page
index will be the same as thecurrent_page
index.Here's the
data
parameter js console output frommorphTo_select_ajax.blade.php@processResult#200
if there's only two pages of data to return:The code to decide whether to paginate obviously fails as it thinks the current page is the last page.
I fixed this by copying to the code from
select2_from_ajax.blade.php
inprocessResults: function (data, params)
at line 208:Is it a bug in the latest version of Backpack?
After I run
composer update backpack/crud
the bug... is it still there?Yup, still there in:
"backpack/crud": "^6.7",
"backpack/pro": "^2.2",
Backpack, Laravel, PHP, DB version
When I run
php artisan backpack:version
the output is:The text was updated successfully, but these errors were encountered: