From 9f128d546df351815e7a681b73877c82e9862a61 Mon Sep 17 00:00:00 2001 From: Dmytro Kulyk Date: Wed, 17 Mar 2021 20:51:20 +0200 Subject: [PATCH] Register watcher for closest component with form --- resources/js/components/FormField.vue | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/resources/js/components/FormField.vue b/resources/js/components/FormField.vue index 70f7923..2bb8044 100644 --- a/resources/js/components/FormField.vue +++ b/resources/js/components/FormField.vue @@ -23,7 +23,7 @@ props: ['resourceName', 'resourceId', 'field'], mounted() { - this.registerDependencyWatchers(this.$root, function() { + this.registerDependencyWatchers(this.findRootComponent(), function() { this.updateDependencyStatus(); }); }, @@ -36,7 +36,18 @@ }, methods: { + findRootComponent() { + let parent = this.$parent, el = this.$el; + while (parent) { + do { + if (el.tagName === 'FORM') return parent; + el = el.parentElement; + } while (el && parent.$el !== el) + parent = parent.$parent + } + return this.$root + }, // @todo: refactor entire watcher procedure, this approach isn't maintainable .. registerDependencyWatchers(root, callback) { callback = callback || null;