-
-
Notifications
You must be signed in to change notification settings - Fork 928
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Choosing a sort by option automatically sends the sort_by url parameter
- Loading branch information
1 parent
17890a8
commit 2d1d794
Showing
3 changed files
with
42 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Controller } from "@hotwired/stimulus" | ||
|
||
// Connects to data-controller="gem-sort" | ||
export default class extends Controller { | ||
static targets = ["form", "select"] | ||
connect() { | ||
this.selectTarget.onchange = () => this.formSubmit(); | ||
} | ||
|
||
formSubmit = () => { | ||
this.formTarget.submit(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,25 @@ | ||
<div class="sorting"> | ||
<%= form_with url: profile_path(@user&.handle), method: :get do |f| %> | ||
<%= | ||
form_with( | ||
data: { | ||
"controller": "gem-sort", | ||
"gem-sort-target": "form", | ||
}, | ||
method: :get, | ||
url: profile_path(@user&.handle) | ||
) do |f| | ||
%> | ||
<%= f.label :sort_by, class: "t-text--s"%> | ||
<%= f.select :sort_by, options_for_select([["Name", "name"], ["Downloads", "downloads"]]) %> | ||
<%= f.submit "Sort" %> | ||
<%= | ||
select_tag :sort_by, | ||
options_for_select( | ||
[ | ||
["Name", "name"], | ||
["Downloads", "downloads"] | ||
], | ||
params[:sort_by] || "downloads" | ||
), | ||
data: { "gem-sort-target" => "select" } | ||
%> | ||
<% end %> | ||
</div> |