xiaohuilam / laravel-admin-select2

π’‚π’”π’šπ’π’„ 𝒔𝒆𝒍𝒆𝒄𝒕/π’Žπ’π’“π’‘π’‰π‘Ίπ’†π’π’†π’„π’• 𝒇𝒐𝒓 𝒍𝒂𝒓𝒂𝒗𝒆𝒍 π’‚π’…π’Žπ’Šπ’
MIT License
41 stars 4 forks source link

The options are not populating #42

Open jicksonjohnson opened 3 years ago

jicksonjohnson commented 3 years ago

$form->select('item_id', 'SKU')->match(function ($keyword) { return Product::where('sku', 'LIKE', '%' . $keyword . '%')->select([DB::raw('sku AS text'), DB::raw('product_id AS id')])->latest(); });

the above code not giving me any listing. Showing "Result could not be loaded" message always.

just for your reference, below is the actual code I was using before. $products = DB::table('products')->pluck('sku','product_id') $form->select('item_id','SKU')->options($products)->rules('required'); I am trying your package only because speed up the search process. the total records of products I have is 30K + and listing all in select box is causing load issue and making it as a searchable result is a better solution.

jicksonjohnson commented 3 years ago

another update,

I haven't mentioned that, I am using this select inside form hasMany also this form is a step form ( using class Encore\Admin\Widgets\StepForm; )

$form->hasMany('purchased_items','Purchased Items', function (NestedForm $form) use ($products) { $form->select('item_id', 'SKU')->match(function ($keyword) { return Product::where('sku', 'LIKE', '%' . $keyword . '%') ->select([DB::raw('sku AS text'), DB::raw('product_id AS id')]) ->latest(); }); });

I found the select is working fine if I use inside a normal admin form

jicksonjohnson commented 3 years ago

found that processResults of select2 JS extended inside LaravelAdminExt\Select2\Traits\FormTrait is not calling or working while using select inside stepForm

xiaohuilam commented 3 years ago

I will look into this issue ASAP but not now (maybe tomorrow), because it's last day of chinese spring festival. sorry

jicksonjohnson commented 3 years ago

thank you so much for replying. when you become free, please have a look.

between I am adding few info. not sure whether these will help to find the cause.

  1. the extended select is working fine while we use inside a normal admin form ( use Encore\Admin\From )

  2. its not working while we use inside a hasMany relation in any form type

Screen Shot 2021-02-16 at 11 50 41 PM
  1. it's not working inside a stepForm. many of time I got internal server error on the ajax request. I am not sure whether this has any link with the route name were the form is located. below is the error related to that from log

`local.ERROR: Call to undefined method Illuminate\Database\Eloquent\Builder::toJson() {"userId":1,"exception":"[object] (BadMethodCallException(code: 0): Call to undefined method Illuminate\Database\Eloquent\Builder::toJson() at /var/www/html/vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php:50) [stacktrace]

0 /var/www/html/vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php(36): Illuminate\Database\Eloquent\Builder::throwBadMethodCallException()

1 /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(1511): Illuminate\Database\Eloquent\Builder->forwardCallTo()

2 /var/www/html/app/Admin/FlatGrid/Steps/ChooseCompany.php(45): Illuminate\Database\Eloquent\Builder->__call()

3 /var/www/html/vendor/xiaohuilam/laravel-admin-select2/src/Traits/FormTrait.php(33): App\Admin\FlatGrid\Steps\ChooseCompany->App\Admin\FlatGrid\Steps\{closure}()`

xiaohuilam commented 3 years ago

I see that, it is a bug, maybe there's no stepForm that while, when this plugin initialized. And it must support inside stepForm anyway, or it is so fail to tell other it is powerful extension.

Fix soon.