Search code examples
laravelvue.jscustom-fieldslaravel-nova

DigitalCreative Conditional Container Error in Laravel Nova


I have created a custom field in laravel nova and wrapped it around a conditional container. When the toggle is set to true the custom field shows up but in this case in the console I get an error:

TypeError: Cannot read properties of undefined (reading 'attribute')
    at a.registerDependencyWatchers (conditional-container:2:161895)
    at a.registerItSelf (conditional-container:2:161625)
    at hook:mounted (conditional-container:2:165311)
    at Ft (vendor.js?id=3cad38f9441f25bd1c3d:1:1137616)
    at a.n (vendor.js?id=3cad38f9441f25bd1c3d:1:1139350)
    at Ft (vendor.js?id=3cad38f9441f25bd1c3d:1:1137616)
    at t.$emit (vendor.js?id=3cad38f9441f25bd1c3d:1:1159781)
    at en (vendor.js?id=3cad38f9441f25bd1c3d:1:1151520)
    at Object.insert (vendor.js?id=3cad38f9441f25bd1c3d:1:1146526)
    at x (vendor.js?id=3cad38f9441f25bd1c3d:1:1186216)

The code in my User Resource looks like this:

use Davidpiesse\NovaToggle\Toggle;
use App\Nova\Fields\Associatecsrcompanyandjobsfield;


            ConditionalContainer::make([
                Toggle::make("Assign user to specific jobs/companies", "assign_user_to_jobs_or_companies")
                    ->default(false)
                    ->falseLabel("NO")
                    ->trueLabel("YES")
                    ->showLabels()
                    ->hideFromIndex(),
            ])->if('role = "Call Center Admin" OR role = "Call Center Rep"'),
            
            ConditionalContainer::make([
                Associatecsrcompanyandjobsfield::make('Associate CSR Company And Jobs'),
            ])->if('assign_user_to_jobs_or_companies = "true"'),

Once I have filled all the input fields and try to save I get another error, I don't know if they are related or it's from my custom field since there's not much shared about the root cause of the errors. My custom field is comprised of two v-select accepts multiple options and a checkbox. The first v-select is of companies and then when you choose companies the other two fields show up one for jobs and a checkbox to choose if you want all jobs shown in the v-select for jobs. The error when I try to save is:

TypeError: Cannot read properties of undefined (reading 'status')
    at a.<anonymous> (app.js?id=fad0f795d1559123aa93:1:58950)
    at k (app.js?id=fad0f795d1559123aa93:1:588288)
    at Generator._invoke (app.js?id=fad0f795d1559123aa93:1:588076)
    at e.<computed> [as next] (app.js?id=fad0f795d1559123aa93:1:588467)
    at o (app.js?id=fad0f795d1559123aa93:1:799545)
    at app.js?id=fad0f795d1559123aa93:1:799686
    at new Promise (<anonymous>)
    at new t (app.js?id=fad0f795d1559123aa93:1:908615)
    at a.<anonymous> (app.js?id=fad0f795d1559123aa93:1:799480)
    at a.<anonymous> (app.js?id=fad0f795d1559123aa93:1:59367)

Solution

  • In my custom field component, I added this line and it solved the issue:

    import { FormField, HandlesValidationErrors } from 'laravel-nova';
    mixins: [FormField, HandlesValidationErrors],