From 3d8eade014be6740e2fb162040390e3ed4d306a1 Mon Sep 17 00:00:00 2001 From: Ryan Mitchell Date: Mon, 11 Dec 2023 18:00:57 +0000 Subject: [PATCH] [4.x] Prevent events being added to an element that doesn't exist when in grid table mode (#9130) Check we have a label to add event to --- .../js/components/fieldtypes/bard/BardFieldtype.vue | 9 ++++++--- .../components/fieldtypes/markdown/MarkdownFieldtype.vue | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/resources/js/components/fieldtypes/bard/BardFieldtype.vue b/resources/js/components/fieldtypes/bard/BardFieldtype.vue index e9873150dd..7727b2486b 100644 --- a/resources/js/components/fieldtypes/bard/BardFieldtype.vue +++ b/resources/js/components/fieldtypes/bard/BardFieldtype.vue @@ -346,9 +346,12 @@ export default { this.$store.commit(`publish/${this.storeName}/setFieldSubmitsJson`, this.fieldPathPrefix || this.handle); this.$nextTick(() => { - document.querySelector(`label[for="${this.fieldId}"]`).addEventListener('click', () => { - this.editor.commands.focus(); - }); + let el = document.querySelector(`label[for="${this.fieldId}"]`); + if (el) { + el.addEventListener('click', () => { + this.editor.commands.focus(); + }); + } }); }, diff --git a/resources/js/components/fieldtypes/markdown/MarkdownFieldtype.vue b/resources/js/components/fieldtypes/markdown/MarkdownFieldtype.vue index dc4e21586b..2657b3d4d1 100644 --- a/resources/js/components/fieldtypes/markdown/MarkdownFieldtype.vue +++ b/resources/js/components/fieldtypes/markdown/MarkdownFieldtype.vue @@ -197,9 +197,12 @@ export default { mounted() { this.initToolbarButtons(); - document.querySelector(`label[for="${this.fieldId}"]`).addEventListener('click', () => { - this.codemirror.focus(); - }); + let el = document.querySelector(`label[for="${this.fieldId}"]`); + if (el) { + el.addEventListener('click', () => { + this.codemirror.focus(); + }); + } }, methods: {