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

Bug fix prototypes populate #333

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion app/views/spree/admin/prototypes/_prototypes.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</thead>
<tbody>
<% @prototypes.each do |prototype| %>
<tr id="row_<%= prototype.id %>" data-hook="available_row">
<tr id="row_<%= prototype.id %>" data-turbo-prefetch="false" data-hook="available_row">
<td><%= prototype.name %></td>
<td class="actions">
<span class="d-flex justify-content-end">
Expand Down
17 changes: 14 additions & 3 deletions app/views/spree/admin/prototypes/select.js.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
<% @prototype_properties.sort_by{ |prop| -prop[:id] }.each do |prop| %>
$("a.spree_add_fields").click();
$(".product_property.fields:first input[type=text]:first").val("<%= prop.name %>");
<% @prototype_properties.sort_by { |prop| -prop[:id] }.each do |prop| %>
var lastField = $(".product_property.fields").last().find("input[type=text]").first();

if (lastField.val().trim() === "") {
// If the last field is empty, populate it with the property name
lastField.val("<%= j(prop.name) %>");
} else {
// Simulate clicking the "Add Product Properties" button
$("#contentHeaderRow a.spree_add_fields").click();

// After adding, get the new last field
lastField = $(".product_property.fields").last().find("input[type=text]").first();
lastField.val("<%= j(prop.name) %>");
}
<% end %>
Loading