Skip to content

Commit b77c297

Browse files
authored
Fix scanning new barcode item issue (#4592) (#4731)
1 parent c11e343 commit b77c297

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

app/views/barcode_items/create.js.erb

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ $('#trigger-field-id').val('');
1212
// Notify the user
1313
toastr.success("Barcode Added to Inventory");
1414

15-
// Locate the row where the barcode was entered from
16-
line_item = $('#' + source_field).closest('.nested-fields');
17-
// Set the values in the form. This is replicating some logic from barcode_items.js.erb
18-
$(line_item).find('[data-quantity]').val(quantity);
19-
$(line_item).find('[value="' + item_id + '"]').attr("selected", true);
20-
$('#__add_line_item').trigger('click');
21-
$("input.__barcode_item_lookup").last().focus();
15+
// Trigger the capture_entry/barcode_item_lookup functions with a return keypress
16+
// which fills in the item name and quantity, adds new item, and changes focus
17+
return_keypress = $.Event( "keypress", { which: 13 } )
18+
$("input.__barcode_item_lookup").last().trigger(return_keypress);

spec/system/donation_system_spec.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,7 @@
490490
click_on "Save"
491491
end
492492

493+
# form updates
493494
within "#donation_line_items" do
494495
barcode_field = page.find(:xpath, "//input[@id='_barcode-lookup-0']").value
495496
expect(barcode_field).to eq(new_barcode)
@@ -498,7 +499,12 @@
498499
item_field = page.find(:xpath, "//select[@id='donation_line_items_attributes_0_item_id']").value
499500
expect(item_field).to eq(Item.first.id.to_s)
500501
end
501-
# form updates
502+
503+
# new line item was added and has focus
504+
within "#donation_line_items" do
505+
expect(page).to have_xpath("//input[@id='_barcode-lookup-1']")
506+
expect(page).to have_css('#_barcode-lookup-1', focused: true)
507+
end
502508
end
503509

504510
context "When the barcode is a global barcode" do

0 commit comments

Comments
 (0)