Skip to content

Commit

Permalink
dependent_fields_frame: update URL from src of ancestor turbo_frame
Browse files Browse the repository at this point in the history
  • Loading branch information
pascallaliberte committed Nov 9, 2024
1 parent bd25aa7 commit 54c9f43
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}

0 comments on commit 54c9f43

Please sign in to comment.