epartment / nova-dependency-container Goto Github PK
View Code? Open in Web Editor NEWA Laravel Nova field container allowing to depend on other fields values
License: MIT License
A Laravel Nova field container allowing to depend on other fields values
License: MIT License
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.
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(),
]
),
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),
Good plugin, thanks Man! Will be nice, if this extension can be worked with https://novapackages.com/packages/fourstacks/nova-checkboxes or some other pseudo checkboxes. I try use dependsOnCustomComponent, but it not worked (
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!!
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.
nova-dependency-container/resources/js/components/FormField.vue
Lines 85 to 91 in c0884a0
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.
After usin gthe DependencyContainer, if you go in to edit the resource, you have to deselect the dependsOn and re select it in order to see the values.
Is there anyway to show the dependent containers on page load from an edit ?
***Update
This was an error on my end. The column referenced needs to be an INT and I had it as a VARCHAR.'
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
Hello ! thanks in advance !
Edited, all right!
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.
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.
I think this package was not working with the latest versions of Nova?
I currently switched to the latest 2.0.6 (and wasn't doing anything at all)
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?
It doesn't work with https://github.com/spatie/nova-translatable, could someone help me identify and solve the problem?
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.
@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.
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.
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.
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 :)
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'),
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(),
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';
}),
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(),
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.
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'),
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.
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?
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.
If a route is not found then instead of 404, the application redirects to
/nova-api/scripts/nova-dependency-container when logged in
I have my route as below
Route::get('/myroute/{dynamic-uri}','MyControllerController@mymethod');
Then if i visit
/myroute --- it redirects to /nova-api/scripts/nova-dependency-container with the js file
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?
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(),
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?
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'),
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?
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(),
Can this package be used within the fields method of an action also?
I need make nova-checkboxes work with nova-dependency-container on a specific checkbox.
Could you help me?
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)
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;
This package looks good but I am not able to use it with the package.
Can anyone help ?
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.
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'),
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.
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),
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
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.
On submit of the form, if there is a boolean checkbox inside a dependency container, the value is getting passed as string "true" instead of true. Help!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.