Skip to content

Commit

Permalink
fixes for nova 3.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
duckzland committed Apr 11, 2020
1 parent 98e9ef2 commit 0905cca
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/.idea
/vendor
/node_modules
auth.json
package-lock.json
composer.phar
composer.lock
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require-dev": {
"laravel/nova": "~2.0"
"laravel/nova": "^3.0"
}
}
2 changes: 1 addition & 1 deletion dist/js/field.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"acorn": "^6.4.1",
"cross-env": "^5.0.0",
"laravel-mix": "^4.1.2",
"laravel-nova": "^1.0",
"laravel-nova": "^1.2.2",
"laravel-vapor": "^0.4.0",
"minimist": "^1.2.2",
"resolve-url-loader": "3.1.0",
"serialize-javascript": "^2.1.1",
Expand Down
20 changes: 14 additions & 6 deletions resources/js/components/NestedFormAdd.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ export default {
props: {
field: {
type: Object,
required: true
required: true,
schema: {},
children: []
}
},
Expand All @@ -31,9 +33,15 @@ export default {
*/
addChild() {
let maxKey = 0;
if(this.field.children.length){
if(this.field.children && this.field.children.length){
maxKey = this.field.children[this.field.children.length - 1].key || Math.max.apply(Math, this.field.children.map(({ id }) => id));
}
if (!this.field.schema) {
this.field.schema = {};
}
if (!this.field.children) {
this.field.children = [];
}
this.field.schema.key = maxKey + 1;
this.field.children.push(this.replaceIndexesInSchema(this.field));
},
Expand All @@ -46,7 +54,7 @@ export default {
replaceIndexesInSchema(field) {
const schema = JSON.parse(JSON.stringify(field.schema))
schema.fields.forEach(field => {
schema.fields && schema.fields.forEach(field => {
if (field.schema) {
field.schema = this.replaceIndexesInSchema(field)
}
Expand All @@ -66,10 +74,10 @@ export default {
}
})
schema.heading = schema.heading.replace(
schema.heading = schema.heading && schema.heading.replace(
this.field.indexKey,
this.field.children.length + 1
)
) || ''
return schema
}
Expand All @@ -79,7 +87,7 @@ export default {
* On created.
*/
created() {
for (let i = this.field.children.length; i < this.field.min; i++) {
for (let i = this.field.children && this.field.children.length || 0; i < this.field.min; i++) {
this.addChild()
}
}
Expand Down
2 changes: 1 addition & 1 deletion resources/js/components/NestedFormField.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div class="relative">
<template v-if="shouldDisplay()">
<template v-if="field.children.length > 0">
<template v-if="field.children && field.children.length > 0">
<card
:class="{ 'overflow-hidden': field.panel && !index }"
:key="child.id || child.key"
Expand Down
4 changes: 4 additions & 0 deletions src/NestedForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ class NestedForm extends Field
*/
public function __construct(string $name, $attribute = null, $resource = null)
{

parent::__construct($name, $attribute);
$resource = $resource ?? ResourceRelationshipGuesser::guessResource($name);

Expand All @@ -194,6 +195,9 @@ public function __construct(string $name, $attribute = null, $resource = null)
$this->keyName = (new $this->resourceClass::$model)->getKeyName();
$this->viaResource = app(NovaRequest::class)->route('resource');
$this->returnContext = $this;

// Nova ^3.3.x need this to fix cannot add relation on create mode
$this->resolve(app(NovaRequest::class)->model());
}

/**
Expand Down

0 comments on commit 0905cca

Please sign in to comment.