diff --git a/bullet_train-fields/app/javascript/controllers/dependent_fields_frame_controller.js b/bullet_train-fields/app/javascript/controllers/dependent_fields_frame_controller.js index b64664dd8..995a9acc2 100644 --- a/bullet_train-fields/app/javascript/controllers/dependent_fields_frame_controller.js +++ b/bullet_train-fields/app/javascript/controllers/dependent_fields_frame_controller.js @@ -32,7 +32,7 @@ export default class extends Controller { } constructNewUrlUpdatingField(fieldName, fieldValue) { - const url = new URL(window.location.href) + const url = new URL(this.currentUrl) url.searchParams.set(fieldName, fieldValue) return url.href @@ -81,4 +81,9 @@ export default class extends Controller { field.value = value } + + get currentUrl() { + const turboFrameWithUrl = this.element.closest("turbo-frame[src]") + return turboFrameWithUrl ? turboFrameWithUrl.src : window.location.href + } }