LaravelRUS / SleepingOwlAdmin

🦉 Administrative interface builder for Laravel (Laravel admin)
http://sleepingowladmin.ru/
MIT License
799 stars 216 forks source link

dependentselect inside hasmany #1345

Closed eugenem closed 6 months ago

eugenem commented 1 year ago

Is such thing even possible? I'm getting 404 error as admin is trying to load dependent value from /admin/po_lines/dependent-select/po_lines%5B1%5D%5Bproduct_id%5D/1 and I'm at /admin/pos/2/edit I mean I don't even have a section for po-lines

        return AdminForm::panel()->addBody( [
            AdminFormElement::date( 'date', 'תאריך' )->required(),
            AdminFormElement::select('supplier_id', 'ספק', new Supplier())
                ->setDisplay('name'),
            AdminFormElement::html('<h4>מוצרים</h4>'),
            AdminFormElement::hasMany( 'po_lines', [AdminFormElement::columns([[
                #AdminFormElement::select('product_id', 'מוצר', new Product())
                #    ->setDisplay('full_name')],[
                AdminFormElement::dependentselect('product_id', 'מוצר')
                    ->setModelForOptions(Product::class, 'full_name')
                    ->setDataDepends(['supplier_id'])
                    ->setLoadOptionsQueryPreparer(function($item, $query) {
                        return $query->where('supplier_id', $item->getDependValue('supplier_id'));
                    })],[
                AdminFormElement::number( 'quantity', "כמות" )->required()],
            ])]),
            AdminFormElement::number( 'amount', "סה״כ" )->required(),
            AdminFormElement::view('admin.po_total', []),
        ] );
Aglok commented 8 months ago

now there is such an possible, fix work with element, if need use select inside related element add method setIsOutsideTargetDepend(false).