Skip to content

Commit

Permalink
Merge pull request #27 from TMCApplications/dependant-field
Browse files Browse the repository at this point in the history
Add Dependent Fields Support
  • Loading branch information
lptn authored Mar 7, 2023
2 parents 58bf666 + c222636 commit 9a8f87b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion dist/js/field.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"/js/field.js": "/js/field.js?id=f8a31dff3bb6ddd67f06f23de2ecb78b"
"/js/field.js": "/js/field.js?id=1acbd77788edad6658ba206abc039e92"
}
2 changes: 1 addition & 1 deletion nova.mix.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class NovaExtension {
...(webpackConfig.resolve.alias || {}),
'laravel-nova': path.join(
__dirname,
'../../vendor/laravel/nova/resources/js/mixins/packages.js'
'/vendor/laravel/nova/resources/js/mixins/packages.js'
),
};

Expand Down
33 changes: 17 additions & 16 deletions resources/js/components/FormField.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<DefaultField
:field="field"
:field="currentField"
:errors="errors"
:show-help-text="showHelpText"
:full-width-content="true"
Expand All @@ -22,10 +22,11 @@
:style="{minHeight: containerHeight}"
ref="editor"
@load="editorLoaded"
:locale=field.config.locale
:projectId=field.config.projectId
:templateId="field.value ? null : field.config.templateId"
:options=unProxy(field.config)
:locale=currentField.config.locale
:projectId=currentField.config.projectId
:templateId="currentField.value ? null : currentField.config.templateId"
:options=unProxy(currentField.config)
:key=currentField.config.key
/>
</div>
</template>
Expand All @@ -34,12 +35,12 @@

<script>
import UnlayerEditor from './UnlayerEditor.vue';
import { FormField, HandlesValidationErrors } from 'laravel-nova'
import { DependentFormField, HandlesValidationErrors } from 'laravel-nova'
const defaultHeight = '700px';
export default {
mixins: [FormField, HandlesValidationErrors],
mixins: [DependentFormField, HandlesValidationErrors],
components: {
UnlayerEditor,
Expand All @@ -49,23 +50,23 @@
computed: {
containerHeight: function () {
return this.field.height || defaultHeight;
return this.currentField.height || defaultHeight;
},
},
methods: {
/** Register listeners, load initial template, etc. */
editorLoaded() {
if (this.field.value !== null) {
this.$refs.editor.loadDesign(this.unProxy(this.field.value));
if (this.currentField.value !== null) {
this.$refs.editor.loadDesign(this.unProxy(this.currentField.value));
}
/** @see https://docs.unlayer.com/docs/events */
window.unlayer.addEventListener('design:loaded', this.handleDesignLoaded);
window.unlayer.addEventListener('design:updated', this.handleDesignUpdated);
window.unlayer.addEventListener('image:uploaded', this.handleImageUploaded);
this.loadPlugins(this.field.plugins);
this.loadPlugins(this.currentField.plugins);
},
/**
Expand Down Expand Up @@ -97,8 +98,8 @@
* @property {FormData} formData
*/
fill(formData) {
formData.append(this.field.attribute, JSON.stringify(this.design));
formData.append(`${this.field.attribute}_html`, this.html);
formData.append(this.currentField.attribute, JSON.stringify(this.design));
formData.append(`${this.currentField.attribute}_html`, this.html);
},
/**
Expand All @@ -111,7 +112,7 @@
});
Nova.$emit('unlayer:design:loaded', {
inputName: this.field.attribute,
inputName: this.currentField.attribute,
payload: loadedDesign,
});
},
Expand Down Expand Up @@ -177,7 +178,7 @@
}
Nova.$emit('unlayer:design:updated', {
inputName: this.field.attribute,
inputName: this.currentField.attribute,
payload: changeLog,
});
},
Expand All @@ -187,7 +188,7 @@
*/
handleImageUploaded(imageData) {
Nova.$emit('unlayer:image:uploaded', {
inputName: this.field.attribute,
inputName: this.currentField.attribute,
payload: imageData,
});
},
Expand Down
2 changes: 2 additions & 0 deletions src/Unlayer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Support\Facades\App;
use Laravel\Nova\Fields\Field;
use Laravel\Nova\Fields\SupportsDependentFields;
use Laravel\Nova\Http\Requests\NovaRequest;

/**
Expand All @@ -14,6 +15,7 @@
*/
class Unlayer extends Field
{
use SupportsDependentFields;
public const MODE_EMAIL = 'email';
public const MODE_WEB = 'web';

Expand Down

0 comments on commit 9a8f87b

Please sign in to comment.