Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Which is syntax of actionfield method in tab of the component ? #302

Open
sergeynilov opened this issue Nov 6, 2024 · 0 comments
Open

Comments

@sergeynilov
Copy link

sergeynilov commented Nov 6, 2024

In manuals https://github.com/eminiarts/nova-tabs?tab=readme-ov-file#Installation I read example code :

       return [
            Tabs::make('Client Custom Details', [
                Tab::make('Address', [
                    ID::make('Id', 'id'),
                    Text::make('Name', 'name')->hideFromDetail(),
                ]),
                Tab::make('Invoices', [
                    HasMany::make('Invoices'),
                ]),
                Tab::make('Actions', [
                    $this->actionfield(), // Add Actions whererver you like.
                ]),
            ]),
        ];

with actionfield method I suppose that I can on 'Actions' to show some action, just similar as I do in resource :

    public function actions(NovaRequest $request)
    {
        return [
            new ExportUsers,
            new \Cog\Laravel\Nova\Ban\Actions\Ban(),
            new \Cog\Laravel\Nova\Ban\Actions\Unban()
        ];
    }

So I made in my resource:

    public function fields(NovaRequest $request)
    {
        return [
            Tabs::make(__('Discount'), [
                Tab::make(__('Details'), [
                    ID::make()->sortable(),
                    Text::make(__('Name'), 'name')
                        ->rules('required', 'max:100')->sortable()
                        ->updateRules('unique:discounts,name,{{resourceId}}')
                        ->creationRules('unique:discounts,name,{{resourceId}}')
                        ->sortable()
                        ->textAlign('left')->placeholder('Discount name'),

                    Boolean::make(__('Active'), 'active')->rules('nullable')->sortable(),
                    Date::make(__('Active from'), 'active_from')
                        ->displayUsing(fn($value) => $value ? DateConv::getFormattedDate($value) : '')
                        ->sortable(),
                    Date::make(__('Active till'), 'active_till')
                        ->displayUsing(fn($value) => $value ? DateConv::getFormattedDate($value) : '')
                        ->sortable(),

                    Number::make(__('Minimal quality'), 'min_qty',)->min(1)->max(999999)->step(1),
                    Number::make(__('Maximum quality'), 'max_qty')->min(1)->max(999999)->step(1),
                    Number::make(__('Percent'), 'percent')->min(1)->max(100)->step(1),

                    Number::make(__('Order'), 'sort_order',)->min(1)->max(9999)->step(1),
                    Trix::make(__('description'))
                        ->rules('required')
                        ->hideFromIndex()->showOnPreview()->alwaysShow()->withFiles('public')->fullWidth(),

                    $this->actionfield(new \Cog\Laravel\Nova\Ban\Actions\Ban()), // Add Actions whererver you like.

                ]),

            ]),
            HasManyThrough::make(__('Products')),

        ];

I got error in browser's console :

Detail.vue:216 TypeError: Cannot read properties of undefined (reading 'includes')
at Proxy.getHeadingVisibilityForAttribute (nova-tabs:2:29452)
at nova-tabs:2:33664
at ri (runtime-core.esm-bundler.js:2755:16)
at nova-tabs:2:33522
at ri (runtime-core.esm-bundler.js:2755:16)
at Proxy.<anonymous> (nova-tabs:2:32271)
    at $n (runtime-core.esm-bundler.js:816:16)
    at Ee.fn (runtime-core.esm-bundler.js:5764:26)
    at Ee.run (reactivity.esm-bundler.js:178:19)
    at runtime-core.esm-bundler.js:5814:51
    (anonymous) @ runtime-core.esm-bundler.js:226
    pn @ runtime-core.esm-bundler.js:208
    $n @ runtime-core.esm-bundler.js:853
    (anonymous) @ runtime-core.esm-bundler.js:5764
    run @ reactivity.esm-bundler.js:178
    (anonymous) @ runtime-core.esm-bundler.js:5814
    cn @ runtime-core.esm-bundler.js:158
    On @ runtime-core.esm-bundler.js:357
    On @ runtime-core.esm-bundler.js:367
    Promise.then
    _n @ runtime-core.esm-bundler.js:270
    An @ runtime-core.esm-bundler.js:264
    (anonymous) @ runtime-core.esm-bundler.js:5810
    Ie @ reactivity.esm-bundler.js:373
    Fe @ reactivity.esm-bundler.js:363
    Re @ reactivity.esm-bundler.js:337
    (anonymous) @ reactivity.esm-bundler.js:487
    set @ runtime-core.esm-bundler.js:2986
    initializeComponent @ Detail.vue:216
    await in initializeComponent
    mounted @ Detail.vue:176
    (anonymous) @ runtime-core.esm-bundler.js:2675
    cn @ runtime-core.esm-bundler.js:158
    un @ runtime-core.esm-bundler.js:166
    (anonymous) @ runtime-core.esm-bundler.js:2655
    Sn @ runtime-core.esm-bundler.js:325
    J @ runtime-core.esm-bundler.js:6335
    mount @ runtime-core.esm-bundler.js:3824
    (anonymous) @ runtime-dom.esm-bundler.js:1431
    liftOff @ app.js:213
    (anonymous) @ 4?products_page=1&products_filter=W3siQXBwXFxOb3ZhXFxGaWx0ZXJzXFxQcm9kdWN0QnlCcmFuZCI6IiJ9LHsiQXBwXFxOb3ZhXFxGaWx0ZXJzXFxQcm9kdWN0QnlTdGF0dXMiOiIifSx7IlJwalxcRGF0ZXJhbmdlcGlja2VyXFxEYXRlcmFuZ2VwaWNrZXIiOm51bGx9XQ%3D%3D:66
    Show 25 more frames
    Show less
    nova-tabs:2 Uncaught TypeError: Cannot read properties of undefined (reading 'length')
    at nova-tabs:2:28906

I tried to move `actionfield` under Tab :
    public function fields(NovaRequest $request)
    {

        return [
            Tabs::make(__('Discount'), [
                Tab::make(__('Details'), [
                    ID::make()->sortable(),
                    Text::make(__('Name'), 'name')
                        ->rules('required', 'max:100')->sortable()
                        ->updateRules('unique:discounts,name,{{resourceId}}')
                        ->creationRules('unique:discounts,name,{{resourceId}}')
                        ->sortable()
                        ->textAlign('left')->placeholder('Discount name'),

                    Boolean::make(__('Active'), 'active')->rules('nullable')->sortable(),
                    Date::make(__('Active from'), 'active_from')
                        ->displayUsing(fn($value) => $value ? DateConv::getFormattedDate($value) : '')
                        ->sortable(),
                    Date::make(__('Active till'), 'active_till')
                        ->displayUsing(fn($value) => $value ? DateConv::getFormattedDate($value) : '')
                        ->sortable(),

                    Number::make(__('Minimal quality'), 'min_qty',)->min(1)->max(999999)->step(1),
                    Number::make(__('Maximum quality'), 'max_qty')->min(1)->max(999999)->step(1),
                    Number::make(__('Percent'), 'percent')->min(1)->max(100)->step(1),

                    Number::make(__('Order'), 'sort_order',)->min(1)->max(9999)->step(1),
                    Trix::make(__('description'))
                        ->rules('required')
                        ->hideFromIndex()->showOnPreview()->alwaysShow()->withFiles('public')->fullWidth(),
                ]),

                Tab::make('Actions', [
                    $this->actionfield(new \Cog\Laravel\Nova\Ban\Actions\Ban(),), // Add Actions whererver you like.
                ]),
            ]),
            HasManyThrough::make(__('Products')),

        ];

I got error :
    Detail.vue:216 TypeError: Cannot read properties of undefined (reading 'includes')
    at Proxy.getHeadingVisibilityForAttribute (nova-tabs:2:29452)
    at nova-tabs:2:33664
    at ri (runtime-core.esm-bundler.js:2755:16)
    at nova-tabs:2:33522
    at ri (runtime-core.esm-bundler.js:2755:16)
    at Proxy.<anonymous> (nova-tabs:2:32271)
    at $n (runtime-core.esm-bundler.js:816:16)
    at Ee.fn (runtime-core.esm-bundler.js:5764:26)
    at Ee.run (reactivity.esm-bundler.js:178:19)
    at R.e.update (runtime-core.esm-bundler.js:5814:51)
(anonymous) @ runtime-core.esm-bundler.js:226
pn @ runtime-core.esm-bundler.js:208
$n @ runtime-core.esm-bundler.js:853
(anonymous) @ runtime-core.esm-bundler.js:5764
run @ reactivity.esm-bundler.js:178
R.e.update @ runtime-core.esm-bundler.js:5814
cn @ runtime-core.esm-bundler.js:158
On @ runtime-core.esm-bundler.js:357
On @ runtime-core.esm-bundler.js:367
Promise.then
_n @ runtime-core.esm-bundler.js:270
An @ runtime-core.esm-bundler.js:264
(anonymous) @ runtime-core.esm-bundler.js:5810
Ie @ reactivity.esm-bundler.js:373
Fe @ reactivity.esm-bundler.js:363
Re @ reactivity.esm-bundler.js:337
(anonymous) @ reactivity.esm-bundler.js:487
set @ runtime-core.esm-bundler.js:2986
initializeComponent @ Detail.vue:216
await in initializeComponent
mounted @ Detail.vue:176
(anonymous) @ runtime-core.esm-bundler.js:2675
cn @ runtime-core.esm-bundler.js:158
un @ runtime-core.esm-bundler.js:166
Rr.t.__weh.t.__weh @ runtime-core.esm-bundler.js:2655
Sn @ runtime-core.esm-bundler.js:325
J @ runtime-core.esm-bundler.js:6335
mount @ runtime-core.esm-bundler.js:3824
t.mount @ runtime-dom.esm-bundler.js:1431
liftOff @ app.js:213
(anonymous) @ 4?products_page=1&products_filter=W3siQXBwXFxOb3ZhXFxGaWx0ZXJzXFxQcm9kdWN0QnlCcmFuZCI6IiJ9LHsiQXBwXFxOb3ZhXFxGaWx0ZXJzXFxQcm9kdWN0QnlTdGF0dXMiOiIifSx7IlJwalxcRGF0ZXJhbmdlcGlja2VyXFxEYXRlcmFuZ2VwaWNrZXIiOm51bGx9XQ%3D%3D:66
Show 25 more frames
Show less
nova-tabs:2 Uncaught TypeError: Cannot read properties of undefined (reading 'length')
    at nova-tabs:2:28906

Please give detailed example how to use actionfield, the manuals have to small info about that...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant