Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't work with nova repeater fields #31

Open
skywalker666 opened this issue Sep 12, 2024 · 1 comment
Open

Doesn't work with nova repeater fields #31

skywalker666 opened this issue Sep 12, 2024 · 1 comment

Comments

@skywalker666
Copy link

When used inside a repeater field (beta in nova4: https://nova.laravel.com/docs/resources/repeater-fields.html) only the first editor works as they all use the same id. demo is quite hard to setup, so I've come up with a solution myself.

--- a/resources/js/components/FormField.vue
+++ b/resources/js/components/FormField.vue
@@ -3,7 +3,7 @@
                 :show-help-text="showHelpText">
     <template #field>
       <editor
-          :id="currentField.attribute"
+          :id="uniqueId(currentField.attribute)"
           v-model="value"
           :api-key="currentField.options.apiKey"
           :cloud-channel="currentField.options.cloudChannel ?? 6"
@@ -20,6 +20,7 @@

 <script>
 import { DependentFormField, HandlesValidationErrors } from 'laravel-nova'
+import uniqueId from 'lodash.uniqueid'
 import Editor from '@tinymce/tinymce-vue'

 export default {
@@ -37,6 +38,7 @@ export default {
   },

   methods: {
+    uniqueId,
     setupProtectContent () {
       if (this.field.options.init.protect) {
         this.field.options.init.protect = this.field.options.init.protect.map((regex) => {

it uses lodash.uniqueid to generate a distinct id for the field. (npm i -S lodash.uniqueid just 1kb). this seems to be working in my case really well, but i'm not sure what other side effects this might have in other cases. so you might like to have a look ;-)

@skywalker666
Copy link
Author

skywalker666 commented Sep 12, 2024

Just saw there's a PR #30 that does about the same with a helper function from tinymce itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant