From fdba33baa3ccb9c502d8a57f287d93ba97b7b4ea Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Tue, 28 Jun 2022 15:03:51 +0200 Subject: [PATCH] Pass the form, and re-init() on object change I can't make angularjs directive synchronized to scope object, this seems to be a hack, but it works. Also add form in the scope (which was not added...) --- .../utils/directives/tags_with_translation.js.coffee | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/assets/javascripts/admin/utils/directives/tags_with_translation.js.coffee b/app/assets/javascripts/admin/utils/directives/tags_with_translation.js.coffee index ef84570f5e..5ab68c43e1 100644 --- a/app/assets/javascripts/admin/utils/directives/tags_with_translation.js.coffee +++ b/app/assets/javascripts/admin/utils/directives/tags_with_translation.js.coffee @@ -3,6 +3,7 @@ angular.module("admin.utils").directive "tagsWithTranslation", ($timeout) -> templateUrl: "admin/tags_input.html" scope: object: "=" + form: "=" tagsAttr: "@?" tagListAttr: "@?" findTags: "&" @@ -18,7 +19,15 @@ angular.module("admin.utils").directive "tagsWithTranslation", ($timeout) -> scope.limitReached = scope.object[scope.tagsAttr].length >= scope.max if scope.max != undefined scope.object[scope.tagListAttr] = (tag.text for tag in scope.object[scope.tagsAttr]).join(",") + scope.$watch "object", (newObject) -> + scope.object = newObject + init() + $timeout -> + init() + + init = -> + return unless scope.object # Initialize properties if necessary scope.tagsAttr ||= "tags" scope.tagListAttr ||= "tag_list"