When use lucky with htmx, i found my project use context.request.query_params
a lot, do we consider add a view helper method?
#1884
-
Most use e.g. you have a search input, and many others 5, 6 input for others query condition.if you want include those query param into search tag, you have to render the following query param(param1,param2,param3) correctly into page to make following code work correct. input(
type: "search",
"hx-target": "#main",
"hx-select": "#main",
...
"hx-include": "[name1='param1'],[name='param2],[name='param3']"
)
div id: "main" do
...
input type: "hidden", name: "param1", value: context.request.query_params["param1"]?.to_s
input type: "hidden", name: "param2", value: context.request.query_params["param2"]?.to_s
input type: "hidden", name: "param3", value: context.request.query_params["param3"]?.to_s
...
end Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Using That way you can set your params with type-safety like |
Beta Was this translation helpful? Give feedback.
Using
context.request.query_params
directly isn't really safe since there's no sanitization happening, and you're not guaranteed to get the proper type you're looking for. In this case you'd really want to take advantage of usingexpose
https://luckyframework.org/guides/frontend/rendering-html#example-using-needs-and-exposeThat way you can set your params with type-safety like
param param1 : Int32
. For your case, if you just need the escape hatch, then I'd suggest making a helper method in yourMainLayout
or in a mixin that can be included in your pages and components.