From 5ea144d2506fe5e28ed7ec2a17b996e6e9310b6d Mon Sep 17 00:00:00 2001 From: Lee Bradley Date: Wed, 27 Nov 2019 14:24:02 +0000 Subject: [PATCH] Have JS work accross different Form IDs Default JS only works on `EditForm` --- javascript/SubsitesTreeDropdownField.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/javascript/SubsitesTreeDropdownField.js b/javascript/SubsitesTreeDropdownField.js index 3964aff..85c917e 100644 --- a/javascript/SubsitesTreeDropdownField.js +++ b/javascript/SubsitesTreeDropdownField.js @@ -8,7 +8,8 @@ onchange: function() { // TODO Data binding between two fields const name = this.attr('name').replace('_SubsiteID', ''); - let field = $('#Form_EditForm_' + name).first(); + const formId = this.closest('form').attr('id'); + let field = $('#' + formId + '_' + name).first(); field.setValue(0); field.refresh(); field.trigger('change'); @@ -21,8 +22,9 @@ */ $('.TreeDropdownField.SubsitesTreeDropdownField').entwine({ getAttributes() { - const fieldName = this.attr('id').replace('Form_EditForm_', ''); - const subsiteID = $('#Form_EditForm_' + fieldName + '_SubsiteID option:selected').val(); + const formId = this.closest('form').attr('id'); + const fieldName = this.attr('id').replace(formId + '_', ''); + const subsiteID = $('#' + formId + '_' + fieldName + '_SubsiteID option:selected').val(); let attributes = this._super(); attributes.data.urlTree += "?" + fieldName + "_SubsiteID=" + subsiteID;