Skip to content

Commit 9a8f87b

Browse files
authored
Merge pull request #27 from TMCApplications/dependant-field
Add Dependent Fields Support
2 parents 58bf666 + c222636 commit 9a8f87b

File tree

5 files changed

+22
-19
lines changed

5 files changed

+22
-19
lines changed

dist/js/field.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/mix-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"/js/field.js": "/js/field.js?id=f8a31dff3bb6ddd67f06f23de2ecb78b"
2+
"/js/field.js": "/js/field.js?id=1acbd77788edad6658ba206abc039e92"
33
}

nova.mix.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class NovaExtension {
2727
...(webpackConfig.resolve.alias || {}),
2828
'laravel-nova': path.join(
2929
__dirname,
30-
'../../vendor/laravel/nova/resources/js/mixins/packages.js'
30+
'/vendor/laravel/nova/resources/js/mixins/packages.js'
3131
),
3232
};
3333

resources/js/components/FormField.vue

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<DefaultField
3-
:field="field"
3+
:field="currentField"
44
:errors="errors"
55
:show-help-text="showHelpText"
66
:full-width-content="true"
@@ -22,10 +22,11 @@
2222
:style="{minHeight: containerHeight}"
2323
ref="editor"
2424
@load="editorLoaded"
25-
:locale=field.config.locale
26-
:projectId=field.config.projectId
27-
:templateId="field.value ? null : field.config.templateId"
28-
:options=unProxy(field.config)
25+
:locale=currentField.config.locale
26+
:projectId=currentField.config.projectId
27+
:templateId="currentField.value ? null : currentField.config.templateId"
28+
:options=unProxy(currentField.config)
29+
:key=currentField.config.key
2930
/>
3031
</div>
3132
</template>
@@ -34,12 +35,12 @@
3435

3536
<script>
3637
import UnlayerEditor from './UnlayerEditor.vue';
37-
import { FormField, HandlesValidationErrors } from 'laravel-nova'
38+
import { DependentFormField, HandlesValidationErrors } from 'laravel-nova'
3839
3940
const defaultHeight = '700px';
4041
4142
export default {
42-
mixins: [FormField, HandlesValidationErrors],
43+
mixins: [DependentFormField, HandlesValidationErrors],
4344
4445
components: {
4546
UnlayerEditor,
@@ -49,23 +50,23 @@
4950
5051
computed: {
5152
containerHeight: function () {
52-
return this.field.height || defaultHeight;
53+
return this.currentField.height || defaultHeight;
5354
},
5455
},
5556
5657
methods: {
5758
/** Register listeners, load initial template, etc. */
5859
editorLoaded() {
59-
if (this.field.value !== null) {
60-
this.$refs.editor.loadDesign(this.unProxy(this.field.value));
60+
if (this.currentField.value !== null) {
61+
this.$refs.editor.loadDesign(this.unProxy(this.currentField.value));
6162
}
6263
6364
/** @see https://docs.unlayer.com/docs/events */
6465
window.unlayer.addEventListener('design:loaded', this.handleDesignLoaded);
6566
window.unlayer.addEventListener('design:updated', this.handleDesignUpdated);
6667
window.unlayer.addEventListener('image:uploaded', this.handleImageUploaded);
6768
68-
this.loadPlugins(this.field.plugins);
69+
this.loadPlugins(this.currentField.plugins);
6970
},
7071
7172
/**
@@ -97,8 +98,8 @@
9798
* @property {FormData} formData
9899
*/
99100
fill(formData) {
100-
formData.append(this.field.attribute, JSON.stringify(this.design));
101-
formData.append(`${this.field.attribute}_html`, this.html);
101+
formData.append(this.currentField.attribute, JSON.stringify(this.design));
102+
formData.append(`${this.currentField.attribute}_html`, this.html);
102103
},
103104
104105
/**
@@ -111,7 +112,7 @@
111112
});
112113
113114
Nova.$emit('unlayer:design:loaded', {
114-
inputName: this.field.attribute,
115+
inputName: this.currentField.attribute,
115116
payload: loadedDesign,
116117
});
117118
},
@@ -177,7 +178,7 @@
177178
}
178179
179180
Nova.$emit('unlayer:design:updated', {
180-
inputName: this.field.attribute,
181+
inputName: this.currentField.attribute,
181182
payload: changeLog,
182183
});
183184
},
@@ -187,7 +188,7 @@
187188
*/
188189
handleImageUploaded(imageData) {
189190
Nova.$emit('unlayer:image:uploaded', {
190-
inputName: this.field.attribute,
191+
inputName: this.currentField.attribute,
191192
payload: imageData,
192193
});
193194
},

src/Unlayer.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Support\Facades\App;
66
use Laravel\Nova\Fields\Field;
7+
use Laravel\Nova\Fields\SupportsDependentFields;
78
use Laravel\Nova\Http\Requests\NovaRequest;
89

910
/**
@@ -14,6 +15,7 @@
1415
*/
1516
class Unlayer extends Field
1617
{
18+
use SupportsDependentFields;
1719
public const MODE_EMAIL = 'email';
1820
public const MODE_WEB = 'web';
1921

0 commit comments

Comments
 (0)