Git Product home page Git Product logo

nova-dependency-container's People

Contributors

almeidafranci avatar bennofication avatar borisson avatar dododedodonl avatar michielkempen avatar mikaelpopowicz avatar milewski avatar niektenhoopen avatar noahnxt avatar ragingdave avatar rk avatar sash avatar stanangeloff avatar theokouzelis avatar tufankilicaslan avatar vkazakevich avatar wesdeboer avatar wize-wiz avatar yaroslawww avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nova-dependency-container's Issues

Visibility of a attribute of the model

Hy guys,

Within the NovaDependencyContainer it's not possible to hide a attribute.

I have a NovaDepencyContainer with 4 attributes. One of them should only be visible in detail-view. The Method exceptOnForms() normally hide the attribute in forms, but actually not when it's within a NovaDependencyContainer.

Maybe this can be fixxed?

The same issue is on all methods:
"onlyOnForm", "hideWhenCreating", etc.

Code Sample:
NovaDependencyContainer::make( $this->ctaFieldsClose($languages) )->hideWhenCreating->dependsOn('primaryCtaType', 1)

private function ctaFieldsClose($languages){ return [ Translatable::make(primaryCtaLabel) ->locales($languages) ->singleLine() ->hideFromIndex(),];}

The hideWhenCreating and hideFromIndex, both doesn't work. I tried several variatons

dependsOnEmpty relation

A dependsOnEmpty relation (opposite of dependsOnNotEmpty) would be really useful. A field is then required only when another one is not filled out. In my case I want to allow users to either fill out a URL field, or select a related resource to link to.

(if this is already possible currently I'd like to know how! Using dependsOn('field', null) doesn't seem to work, at least not for a select field)

question

Hi
there is a question about belongsto.
did not quite understand how dependsOnNotEmpty works.

Suppose I have a cafe, a cafe has a city.
Can I use this package to add editable city fields ('title' and others) to the cafe's resource?

[bug] Header causes exception

I'm treating the NovaDependencyContainer like a panel in a large model to break up field groups. Adding a Heading causes an exception when saving the page.

NovaDependencyContainer::make([
  Header::make('Test Heading'),

  Text::make('My Field')
    ->hideFromIndex(),
])
   ->dependsOn('other', 'value'),

The exception is thrown by line 88, as the fill() method doesn't exist on the Header component.

fill(formData) {
if(this.dependenciesSatisfied) {
_.each(this.field.fields, field => {
field.fill(formData)
})
}
}

Required triggers failed validation even if dependency isn't selected

I have a Boolean::('mybool) and a NovaDependencyContainer:: with dependsOnNotEmpty('mybool') and a text field inside.
The container seems to work fine in toggling the display of the text field, however if I add ->rules('required') to the field inside the dependencyContainer it won't let me update the model unless the text field is filled out even if I have not triggered the boolean to show the text field. Is there a way to only make the field required if the field is visible in the container?

The demo doesn't work for me. (with workaround)

I don't know why, but the demo doesn't work for me.

laravel/framework: v5.7.26
laravel/nova: v1.3.2
epartment/nova-dependency-container: 1.1.1

I used the demo code in resource, the "first_name" text field doesn't appear when "name_format" equals 0. After investigation, I found the value in "name_format" is string. The source code of this package use !== to check it's value and change dependenciesSatisfied to true if they are equal.

I converted the value in "depensOn" property to string that works.

Here is workaround:

class Page extends Resource
{
    use HasDependencies;

    public function fields(Request $request)
    {
        return [

            Select::make('Name format', 'name_format')->options([
                0 => 'First Name',
                1 => 'First Name / Last Name',
                2 => 'Full Name'
            ])->displayUsingLabels(),

            NovaDependencyContainer::make([
                Text::make('First Name', 'first_name')
            ])->dependsOn('name_format', "0"),  // <---- change it to string

        ];
    }
}

Please check the source code or update the demo accordingly. Thanks.

Array/callback support (Feature request)

Maybe a nice feature is making the ability to pass in an array with values on which the value of the input filed gets checked. If the value is in the array then the container should show. Whereas now it only accepts one value per field.

It could look like so
screen shot 2018-10-04 at 3 24 55 pm

Or you could even make it a callback.
screen shot 2018-10-04 at 3 32 51 pm

Problem with DisplayUsing()

Am I doing something wrong here or is DisplayUsing() not supported?
Works fine outside JSON.

Select::make('Effect', 'kw')
    ->rules('required')
    ->options([
        '0.18' => '0.18',
        '0.25' => '0.25',
        '0.37' => '0.37',
        '0.55' => '0.55',
    ])
    ->help('Effect in kW, only numbers.')
    ->displayUsing(function ($kw) {
        return $kw.' kW';
    }),

Trait Not Found

Followed directions and am getting an error. Likely me doing something wrong. Please help?

namespace App\Nova;

use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Number;
use Laravel\Nova\Fields\Select;
use Illuminate\Http\Request;
use Laravel\Nova\Http\Requests\NovaRequest;
use Eparment\NovaDependencyContainer\HasDependencies;

class Customer extends Resource
{
    use HasDependencies;

screenshot-2018 10 23-19-40-52

php artisan nova:publish breaks nova-dependency-container

Launching the command php artisan nova:publish --force the new files app.js and vendor.js from nova are published and obviously these are not compatible with this package because epartment/nova-dependency-container stops working.

dependsOnCustomComponent()

ElementNumber::make('Other','other_hours')->help('(non-billable)'),

NovaDependencyContainer::make('Dependent settings', [
                ElementInput::make('Other Description','other_hours_description')
])->dependsOnNotEmpty('other_hours')->dependsOnCustomComponent('form-element-number')->hideFromIndex(),

I get this error:

Method Epartment\NovaDependencyContainer\NovaDependencyContainer::dependsOnCustomComponent does not exist.

Upon checking the source code, it would appear that method indeed does not exist? I see you added that method in commit here but it's not in your latest release?

Doesn't update dynamically when depending on a BelongsTo field

When depending on a BelongsTo field on initial page load everything is calculated correctly, but then when the field changes nothing happens. I did test with a Select field and it worked fine with that.

I would guess that perhaps something is different with the BelongsTo Vue component compared to the other "standard" components?

Doesn't handle Toggle custom field

This currently doesn't work with the Toggle custom field type:
https://novapackages.com/packages/davidpiesse/nova-toggle

It does correctly hide the dependent option, but changing the toggle does nothing. The code works perfectly if modified to Boolean instead.

Sample:

Toggle::make('Our Option', 'selectable_option')->hideFromIndex(),
NovaDependencyContainer::make('Dependent settings', [
   Trix::make('Details', 'selectable_option_details'),
])->dependsOn('selectable_option', 1)->onlyOnForms(),

Depending on a BelongsTo doesn't work

Doesn't works:

BelongsTo::make('Supplier'),

NovaDependencyContainer::make(...)
                       ->dependsOn('supplier', 4),

Works:

Select::make('Supplier')
      ->options(...),

NovaDependencyContainer::make(...)
                       ->dependsOn('supplier', 4),

I don't understand why. The values are the same, from 1 to 5.

BelongsTo field in DependencyContainer throws exception

When adding a BelongsTo field to a DependencyContainer, Laravel Nova throws a Trying to get property 'resourceClass' of non-object exception.

I'm running version 1.0.2 of the package, with these fields in my resource:

Select::make('Type')->options([
   'internal' => 'Internal link',
   'external' => 'External link',
]),


NovaDependencyContainer::make('Dependent settings', [

   Url::make('Link'),

])->dependsOn('type', 'external')->onlyOnForms(),


NovaDependencyContainer::make('Dependent settings', [

   BelongsTo::make('Page', 'page', PageResource::class),

])->dependsOn('type', 'internal')->onlyOnForms(),

Doesn't work within NovaTab

Nova Tabs allows grouping of fields into tabs:
https://github.com/arsenaltech/nova-tab

When I use a Dependency Container within a tab, it doesn't function when the checkbox is checked. When I move it outside the tab it functions perfectly.

Sample:

new NovaTab(
  'Tab Name',
  [
     Boolean::make('Our Option', 'selectable_option')->hideFromIndex(),
     NovaDependencyContainer::make('Dependent settings', [
        Trix::make('Details', 'selectable_option_details'),
     ])->dependsOn('selectable_option', 1)->onlyOnForms(),
 ]
),

NovaDependencyContainer on BelongsToMany places container in parent panel

When using NovaDependencyContainer on BelongToMany, the rendered result is in the parent panel. It should be detached, like seen below.

            NovaDependencyContainer::make([
                BelongsToMany::make('Event Items'),
            ])->dependsOnNotEmpty('include_event_items'),

Currently renders:
image

Of course, I would like it to look like this:
image

Image Field Type

I am trying to use the default 'Image' field type with this package but it always just defaults the value in the database. I can get the image to upload to my s3 bucket, but somewhere it seems to remove the path value. Other fields all work flawlessly. Is there something obvious I'm doing wrong or this a bug?

NovaDependencyContainer::make([ Image::make('Ad Image','ad_image') ->disk('s3') ->path('ads/'.$currentYear.'/'.$currentMonth.'/banner') ->hideFromIndex() ->prunable(), ])->dependsOn('type', 0),

Depends on unknown value?

Hi!

I have a field that's only required if a BelongsTo field is NOT EMPTY, how do I handle that?

By looking at the code, I can't figure out if it's already an option, but if not, it would be a nice feature.

It could be done the same way as the where clause, where you have an optional argument for the operator.

Belongsto field not getting populated

Thanks for this awesome package for Nova!
I found a bug when trying to use a belongsto field inside the Nova Dependency Container. It is not getting populated. Instead you get an error like "trying to get property of non-object". Field works fine outside the container.

Problem with reference to Event facade in FieldServiceProvider

In boot method the reference to The Laravel event Facade is defined like this:

 public function boot()
    {
        // Override ActionController after NovaServiceProvider loaded
        \Event::listen(NovaServiceProviderRegistered::class, function () {
            app('router')->middleware('nova')->post('/nova-api/{resource}/action', 
                ['uses' => '\Epartment\NovaDependencyContainer\Http\Controllers\ActionController@store']);
        });

        Nova::serving(function (ServingNova $event) {
            Nova::script('nova-dependency-container', __DIR__.'/../dist/js/field.js');
        });
    }

There should be an import like this:

use Illuminate\Support\Facades\Event;

And that should be referenced at line 22 instead.

Error working with hideWhenUpdating, hideWhenCreating, onlyOnForms, exceptOnForms

Hello,

I'm on Nova 1.1.8 and have been having issues trying to get this package to work with Nova's Default Showing/Hiding fields parameters. They don't seem to work when they're placed in NovaDependencyContainer::make() but they act as expected when placed outside of that.

The simple code Illustration:

// Will always display on forms
NovaDependencyContainer::make([
    Text::make('NovaDependencyContainer Except on Forms', 'property')
        ->exceptOnForms(),
])->dependsOn('checkbox', true),

// Will not display on forms
Text::make('Except on Forms', 'property')
    ->exceptOnForms(),

Is this a feature that isn't supported and won't be supported? Or, is it a bug.

Trying to get property of non-object, on boolean

version 1.1.1
nova 1.3.0

Get an error on save/update when I try to depend on a boolean value that should be false.
"Trying to get property 'no_vat' of non-object"

Boolean::make('Vat Exempt', 'no_vat')
->help('Never invoice any vat for this company'),

NovaDependencyContainer::make([
Text::make( 'Vat ID', 'vat_id')->sortable()])
->dependsOn('no_vat', false),

Causes failure for Maatwebsite/Laravel-Nova-Excel package

After installing epartment/nova-dependency-container another package got affected, the Maatwebsite/Laravel-Nova-Excel
and got the wrong data passed to foreach() error when exporting excel data using Maatwebsite/Laravel-Nova-Excel

Dependable MorphTo will not work correctly

When using a MorphTo Field in a Nova Dependency Container, it wil fail. You can select a Client or Department (see example), but then i can't select the specific Client or Department, because of an error.

 $fields[] = NovaDependencyContainer::make([
                     Fields\MorphTo::make('org_level')
                ->types([\App\Nova\OrgLevel\Client::class, \App\Nova\OrgLevel\Department:class]);
                ])->dependsOn('some_other_field', 'some_value');

\\Will result in this error
[2019-06-17 10:39:02] local.ERROR: Call to a member function buildMorphableQuery() on null {"userId":1,"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Call to a member function buildMorphableQuery() on null at <path-to-my-project>

This issue can be traced to:

Laravel\Nova\Http\Controllers\MorphableController.php > index method

$field = $request->newResource()
                        ->availableFields($request)
                        ->firstWhere('attribute', $request->field);

$field will be null and therefore the method will fail with the exception.

Validation not working

When i do:

    public function fields(Request $request)
    {
        return [
            ....
            NovaDependencyContainer::make([
                    Text::make('field')
                        ->rules(['required']),
            ])->dependsOn('main_field', 'some_value'),
        ];
    }

field is not required.

Hidden fields in edit view since Nova 1.3.2

laravel/framework: v5.7.26
laravel/nova: v1.3.2
epartment/nova-dependency-container: 1.1.1

When editing a resource, the dependent fields are hidden by default and require the trigger field to emit a change in order to display again.
This happens since Nova 1.3.2.

Can we have multiple dropdown with dependency container

Hi,
Can we have multiple drop down with dependency container

like this

NovaDependencyContainer::make([
       Select::make('Subject','subject_id')->options()->sortable()->rules('required')->displayUsingLabels(),
])->dependsOn('courses_id', 599),

NovaDependencyContainer::make([
      Select::make('Class','class_id')->options()->sortable()->rules('required')->displayUsingLabels(),
      Select::make(' Chapter','chapter_id')->options()->sortable()->rules('required')->displayUsingLabels(),
      Select::make('Topic','topic_id')->options()->sortable()->rules('required')->displayUsingLabels(),
 ])->dependsOn('subject_id','600'),

Nova Nested Form

@unxsist @michielkempen Unfortunately, it's not working with the package Nova Nested Form.

I use that dependency-container to show certain attributes when something is selected in the form. But when I use NestedForms and I select something in the select-box, nothing happens.

Is there a workaround? Would be great to use both in the same Nova model.

Attach inside fields callback function with Select

I woud like this package to work in this case

BelongsToMany::make('Features')
                ->fields(function () {
                    return [
                        NovaDependencyContainer::make([
                            Select::make('Feature Value', 'feature_value_id')->options(
                                \App\FeatureValue::where('feature_id',3)->get()->pluck('value', 'id')->toArray()
                            )->displayUsingLabels()
                        ])->dependsOn('features', '3'),

                    ];
                }),

Is this possible? How to achieve that?

Add checkbox field

Sometimes we want a more simple way to show certain fields, and the checkbox makes it easier..

Thanks for the package, it is a big help!!

File Field Type

I am unable to use this package with the "File" field type, as the file is never uploaded to the server:

Select::make('Type')->options([
    'article' => 'Article',
    'file'    => 'File',
])->sortable()->displayUsingLabels(),

NovaDependencyContainer::make([
    File::make('File')
        ->disk('local')
])->dependsOn('type', 'file'),

Furthermore, when using validation it's clear that the field's data is not being sent to the server, as validation fails and returns, "The file field is required.":

NovaDependencyContainer::make([
    File::make('File')
        ->disk('local')
        ->rules('required', 'file')
])->dependsOn('type', 'file'),

It's not showing field

It's not showing NovaDependencyContainer field when data is pre loaded
Exemple
This is when screen is loading at first time
screen shot 2018-09-30 at 16 45 13

And this is after change 'Tipo' field
screen shot 2018-09-30 at 16 48 01

Invalid argument supplied for foreach error with checkbox

When using this package on a boolean I get the following error:

Invalid argument supplied for foreach() {"userId":1,"email":"xxxxxx","exception":"[object] (ErrorException(code: 0): Invalid argument supplied for foreach() at \vendor\epartment\

nova-dependency-container\src\NovaDependencyContainer.php:92

My resource is:

Boolean::make('Other qualification', 'qualification_other')
	->hideFromIndex()
	->help('Please specify'),

NovaDependencyContainer::make('Dependent settings', [
	Text::make('Qualification', 'qualification_other_name')
])->dependsOnNotEmpty('qualification_other')->onlyOnForms(),

Problem with displayUsingLabels()

When i do:

...
            NovaDependencyContainer::make([
                Select::make('Select', 'select')
                    ->options([
                        'yes' => 'Yes, please',
                        'no' => 'Not',
                    ])
                    ->displayUsingLabels(),
            ])->dependsOn('some_field', 'some_value'),
        ];

On details of resource select attribute show the key, not label.

Boolean values always are false in dependency container

laravel/framework: v5.7.26
laravel/nova: v1.3.2
epartment/nova-dependency-container: 1.1.1

I have 2 Boolean fields in DependecyContainer

Text::make('Domain'),
NovaDependencyContainer::make([
    Boolean::make('Redirect to www')->rules('required'),
    Boolean::make('Force HTTPS'),
])->dependsOnNotEmpty('domain'),

When I check the checkboxes, The request has the values as true, but the response always is false for these boolean fields.

If I remove the container and just use Boolean fields, everything works as expected.

Invalid argument supplied for foreach()

I'm getting the foreach error when using a checkbox even after double checking against the other checkbox issues on here.

        Boolean::make('Featured', 'featured'),
        NovaDependencyContainer::make('Dependent settings', [
            Number::make('Featured Priority', 'featured_priority')
        ])->dependsOn('featured', true)->onlyOnForms(),

DependsOn "or"

Can you add the ability to set the dependencies as OR conditions? I would like to show a field if FieldA OR FieldB equals a certain value.

Attach to BelongsToMany Relation

Hello,

I have the following use case:
If the app/model is of a certain type, then it's possible to attach to another model with BelongsToMany relation.

So we made a NovaDepencyController on the relation

NovaDependencyContainer::make( [ BelongsToMany::make('certificateTemplate','certificate'), ] )->dependsOn('responseType', 3)

After clicking on "attach" the view is loading in an endless loop.. if I remove the DependencyContainer and only have the BelongsToMany in Code, then there is no problem.

BelongsToMany::make('certificateTemplate','certificate')

I look forward to an answer :)

If fields are named the same thing, always keeps the last value

Hi,

I've added three fields which are all called "Value" but have a different type of Text, Textarea or Boolean. This causes them always to have the last value, even if the nova dependency is not showing those fields. Is there anyway to implement three types for one column?

Code I'm using is below.

            NovaDependencyContainer::make([
                Boolean::make('Value')
                    ->hideFromIndex(),
            ])->dependsOn('type', 'boolean'),

            NovaDependencyContainer::make([
                Text::make('Value')
                    ->hideFromIndex(),
            ])->dependsOn('type', 'text'),

            NovaDependencyContainer::make([
                Textarea::make('Value')
                    ->hideFromIndex()
                    ->alwaysShow(),
            ])->dependsOn('type', 'textarea'),

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.