Skip to content

Commit

Permalink
Add support for BelongsTo and MorphTo relations
Browse files Browse the repository at this point in the history
  • Loading branch information
wize-wiz committed Sep 26, 2019
1 parent f2574c5 commit 37839d0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ A container for grouping fields that depend on other field values. Dependencies

![Demo](https://raw.githubusercontent.com/epartment/nova-dependency-container/master/docs/demo.gif)

### Installation

#### Versions
### Versions

- install v1.2.0 for Laravel v5.8 or v6.x and Nova 2.x
- install v1.1.2 for Laravel v5.7 and Nova v1.x

### Installation

The package can be installed through Composer.

```bash
Expand Down Expand Up @@ -76,6 +77,15 @@ For example a checkbox:

![Demo](https://raw.githubusercontent.com/epartment/nova-dependency-container/master/docs/demo-2.gif)

### Releases

I'm going to abuse this README for versioning ...

- v1.2.1
- fixed support for [BelongsTo](https://nova.laravel.com/docs/1.0/resources/relationships.html#belongsto) and [MorphTo](https://nova.laravel.com/docs/1.0/resources/relationships.html#morphto) fields (@mikaelpopowicz, @dbf)
- v1.2.0
- working version for Laravel 5.8 | 6 and Nova 2.x. (@FastPointGaming, @spaceo, @cdbeaton, @yaroslawww)

### License

The MIT License (MIT). Please see [License File](https://github.com/epartment/nova-dependency-container/blob/master/LICENSE.md) for more information.
2 changes: 1 addition & 1 deletion dist/js/field.js

Large diffs are not rendered by default.

22 changes: 18 additions & 4 deletions resources/js/components/FormField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,10 @@
root.$children.forEach(component => {
if (this.componentIsDependency(component)) {
let belongsTo = component.field.component === 'belongs-to-field';
let attribute = belongsTo ? 'selectedResource' : 'value';
let attribute = this.findWatchableComponentAttribute(component);
component.$watch(attribute, (value) => {
if (belongsTo) {
// @todo: replace with function to set value and move updateDependencyStatus call
if (attribute === 'selectedResource') {
value = (value && value.value) || null;
}
this.dependencyValues[component.field.attribute] = value;
Expand All @@ -58,6 +57,21 @@
})
},
findWatchableComponentAttribute(component) {
let attribute;
switch(component.field.component) {
case 'belongs-to-field':
attribute = 'selectedResource';
break;
case 'morph-to-field':
attribute = 'fieldTypeName';
break;
default:
attribute = 'value';
}
return attribute;
},
componentIsDependency(component) {
if(component.field === undefined) {
return false;
Expand Down

0 comments on commit 37839d0

Please sign in to comment.