Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding draft work on hotwire concept for implementing dependent dropdown #4420

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ gem "mini_racer", "~> 0.12.0"
gem "nokogiri", ">= 1.10.4"
gem "image_processing"
gem "sprockets", "~> 4.2.1"
gem 'requestjs-rails'

group :production do
# Tool to detect unused code through knowing which methods are used in which files.
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,8 @@ GEM
io-console (~> 0.5)
request_store (1.5.1)
rack (>= 1.4)
requestjs-rails (0.0.11)
railties (>= 6.1.0)
responders (3.1.1)
actionpack (>= 5.2)
railties (>= 5.2)
Expand Down Expand Up @@ -768,6 +770,7 @@ DEPENDENCIES
rails-erd
recaptcha
redis (~> 5.2)
requestjs-rails
rolify (~> 6.0)
rspec-rails (~> 6.1.2)
rubocop
Expand Down
8 changes: 8 additions & 0 deletions app/controllers/items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ def update
end
end

def request_units
# print "hello"
print params[:id]
item = Item.find(params[:id])
print item.request_units.inspect

end

def deactivate
item = current_organization.items.find(params[:id])
begin
Expand Down
13 changes: 13 additions & 0 deletions app/javascript/controllers/item_select_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Controller } from "@hotwired/stimulus"
import { post } from "@rails/request.js"

export default class extends Controller {
update_units() {
const item_id = this.element.value
console.log(item_id)
post(`/items/${item_id}/request_units`, {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a get instead of a post?

query: { item_id },
responseKind: 'turbo-stream'
})
}
}
13 changes: 12 additions & 1 deletion app/views/partners/requests/_item_request.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@
<tr>
<td>
<%= field.label :item_id, "Item Requested", {class: 'sr-only'} %>
<%= field.select :item_id, @requestable_items, {include_blank: 'Select an item'}, {class: 'form-control'} %>
<%= field.select :item_id, options_for_select(@requestable_items),
{include_blank: 'Select an item'},
class: 'form-control',
data: {
controller: 'item-select',
action: 'item-select#update_units'
}
%>
</td>
<td>
<%= field.label :quantity, "Quantity", {class: 'sr-only'} %>
<%= field.number_field :quantity, label: false, step: 1, min: 1, class: 'form-control' %>
</td>
<%# <td> %>
<%# <%= field.label :unit, "Units(if applicable)", {class: 'sr-only'} %> %>
<%# <%= field.select :unit, @requestable_items, {include_blank: 'Select an item'}, {class: 'form-control'} %> %>
<%# </td> %>
<td>
<%= remove_element_button "Remove", container_selector: "tr" %>
</td>
Expand Down
1 change: 1 addition & 0 deletions app/views/partners/requests/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<tr>
<th>Item Requested</th>
<th>Quantity</th>
<th>Units(if applicable)</th>
</tr>
</thead>
<tbody class='fields'>
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ def set_up_flipper
delete :deactivate, on: :member
patch :restore, on: :member
patch :remove_category, on: :member
post :request_units, on: :member
end

resources :item_categories, except: [:index]
Expand Down
Loading