Hey …
I have a button_to tag like this in my views:
<%= button_to report_filter_values_path(@report, @filter), data: {"filter-target"=>"searchOutput", "action" =>"click->filter#searchClicked"} do %>
<% end %>
The button text is added dynamically via a stimulus controller. Basically, its a modification on something a user searched on a search box on the same page.
fetchSearch(event) {
var searchQueryTarget = this.searchQueryTarget.value
if(searchQueryTarget !== "") {
var searchString = "Filters on '" + searchQueryTarget + "'"
this.searchOutputTarget.textContent = searchString
}
}
So, in the above Stimulus controller method, I am setting the button text to the value from searchString
. This works perfectly… But now I also need to pass this button text value in the url as params. So, my url should be updated from report_filter_values_path(@report, @filter)
to something like this: report_filter_values_path(@report, @filter, content: "searchStringValue")
. I need this value in my controller, so thought I could pass that as part of the params.
I’m thinking this can be done if I modify the href attribute. But stuck on this approach. If you have any suggestions, please share.
Thank you!
Arjun