nova-element-ui icon indicating copy to clipboard operation
nova-element-ui copied to clipboard

ElementTabsRelations doesn't work on my nova 1.0.12

Open DonDiegoAA opened this issue 6 years ago • 18 comments

I followed the instructions, but the presentation does not change with ElementTabsRelations, no tabs.

ElementTabsRelations::make('Tabs')
            ->addTab('Contacts', BelongsToMany::make('Contacts', 'contacts') )
            ->addTab('Events', BelongsToMany::make('Events', 'events') )
            ->addTab('Documents', HasMany::make('Documents', 'documents') )
            ->activeTab('Contacts'),

DonDiegoAA avatar Sep 05 '18 16:09 DonDiegoAA

Hello, I'll check this soon. I think it's broken in the new version of Nova

fat4lix avatar Sep 05 '18 17:09 fat4lix

Does not work for me either. I was excited to see this feature set.

michaelchunn avatar Sep 05 '18 19:09 michaelchunn

+1, thanks for you time

cloudstudio avatar Sep 09 '18 10:09 cloudstudio

This is a problem. Nova tries to get a related field using the fields()function, but does not find it because the related fields is inside ElementsTabsRelations. To work around this issue, you can override the availableFields() function in your resource, like this.

public function availableFields(NovaRequest $request)
    {
        $fields = $this->fields($request);
        $tabsRelationsField = collect($fields)
            ->first(function($field){
                return get_class($field) == ElementTabsRelations::class;
            });
        $relatedFields = collect($tabsRelationsField->tabs)
            ->map(function($tab){
                return $tab['field']->hideFromDetail();
            })->toArray();

        return new FieldCollection(
            array_values(
                $this->filter(array_merge($fields, $relatedFields))
            )
        );
    }

fat4lix avatar Sep 09 '18 16:09 fat4lix

@fat4lix thanks for all !

I try this solution, but is not working for me :(

No errors, just show relations like normal mode.

cloudstudio avatar Sep 09 '18 18:09 cloudstudio

@cloudstudio Can you show me your fields() function please?

fat4lix avatar Sep 09 '18 18:09 fat4lix

Hello,

I tried your solution too, but still doesn't work for me.

First I had this error: Class 'App\Nova\FieldCollection' not found

Then I add use Laravel\Nova\Fields\FieldCollection; No more error, but still no tabs around my relationships

Her is my fields function:

public function fields(Request $request)
{
    return [
        ID::make()->sortable(),

        Text::make('Type', function () {
            if( $this->category == 'staff' ) {
                return "Staff";
            }elseif( $this->category == 'member' ) {
                return "Member";
            }elseif( $this->category == 'external' ) {
                return "External";
            }
           
        })->onlyOnIndex(),

        RadioButton::make('Type','category')
        ->options([
            'staff' => 'Contact of the federation\'s staff',
            'member' => 'Member',
            'external' => 'External contact',
        ])
        ->default('member') // optional
        ->sortable()
        ->rules('required')->hideFromIndex(),

        Text::make('Name', function () {
            return $this->first_name.' '.$this->last_name;
        })->onlyOnDetail(),
        Text::make('First Name')->sortable()->rules('required', 'max:255')->hideFromDetail(),
        Text::make('Last Name')->sortable()->rules('required', 'max:255')->hideFromDetail(),

        RadioButton::make('Gender')
        ->options([
            'm' => 'Man',
            'f' => 'Woman',
        ])
        ->default('m') // optional
        ->sortable()
        ->rules('required')->hideFromIndex(),

        Text::make('Organisation')->sortable()->rules('max:255'),
        Text::make('Function')->sortable()->rules('max:255')->hideFromIndex(),

        Email::make('Email')->sortable()->rules('nullable', 'email', 'max:255')->clickable()->clickableOnIndex(),
        Text::make('Phone')->sortable()->rules('max:255')->hideFromIndex(),
        Country::make('Country')->displayUsingLabels()->sortable()->rules('max:2')->hideFromIndex(),
        Avatar::make('Photo')->disk('contact')->rules('nullable', 'image','mimes:jpg,jpeg,png,gif')->exceptOnForms(),
        ImageCropper::make('Photo')->disk('contact')->rules('nullable', 'image','mimes:jpg,jpeg,png,gif')->onlyOnForms(),
        Url::make('Twitter')->rules('nullable','url','max:255')->clickable()->hideFromIndex(),
        Url::make('Facebook')->rules('nullable','url','max:255')->clickable()->hideFromIndex(),
        Url::make('Linkedin')->rules('nullable','url','max:255')->clickable()->hideFromIndex(),
        Textarea::make('Followed Topics')->hideFromIndex(),
        Text::make('Working groups',function (){
            $thematicsStr = '';
            foreach ($this->thematics as $key => $value) {
                if( !empty($thematicsStr) ) {
                    $thematicsStr.= "<br/>";    
                }
                $thematicsStr.= '<span style="white-space: pre;"><a href="/backoffice/resources/thematics/'.$value->id.'" class="no-underline dim text-primary font-bold" >'.$value->title.'</a></span>';
                    
            }
            return $thematicsStr;
        })->asHtml()->exceptOnForms(),

        ElementSwitch::make('Active')
          ->falseLabel('No')
          ->trueLabel('Yes')
          ->showLabels()
          ->sortable()->rules('required', 'boolean'),

        ElementTabsRelations::make('Tabs')
            ->addTab('Working group', BelongsToMany::make('Working group','thematics', Thematic::class) )
            ->addTab('Meetings', HasMany::make('Meetings', 'meetings') )
            ->activeTab('meetings')
            ->borderCard()

    ];
}

DonDiegoAA avatar Sep 09 '18 21:09 DonDiegoAA

@fat4lix i remove it, but is something like @DonDiegoAA

cloudstudio avatar Sep 10 '18 22:09 cloudstudio

@fat4lix - any progress on this? The problem persists with Nova 1.0.16. The work around to override availableFields() doesn't solve the problem.

vootrunner avatar Sep 14 '18 15:09 vootrunner

Can confirm, this isn't working in Nova v1.1.3.

XGhozt avatar Sep 29 '18 01:09 XGhozt

@fat4lix - I don't want to be presumptuous, but should we consider this an abandoned project? If you are just swamped with other things, a quick note saying something to that effect would go a long way.

I appreciate the effort that you've put into the package, and I'm not trying to be rude. ElementTabsRelations is the primary reason I started using Element UI, and I don't have the time to fork and fix it on my own.

-Sam

vootrunner avatar Oct 03 '18 22:10 vootrunner

@vootrunner -- hopefully this project isn't dead... but you might want to check out this alternative for tabs: https://github.com/arsenaltech/nova-tab

XGhozt avatar Oct 04 '18 04:10 XGhozt

So this is rendering the vue directives correctly but nothing is being rendered as a tab - just outputs as normal. When inspecting the code I am seeing the proper but those components do not render as expected

johnpaulmedina avatar Oct 06 '18 10:10 johnpaulmedina

Any fixes guys?

n0n0n0n0 avatar Oct 20 '18 06:10 n0n0n0n0

Still not working in 1.1.7

tanthammar avatar Nov 09 '18 14:11 tanthammar

any update for this guys. Because it still not work in 1.2.0

yatinB07 avatar Dec 10 '18 07:12 yatinB07

it looks like this project abandoned

n0n0n0n0 avatar Dec 10 '18 07:12 n0n0n0n0

=(

pirattero avatar Apr 12 '19 19:04 pirattero