Skip to content

Commit

Permalink
prototype populate bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rahul2103 committed Nov 19, 2024
1 parent c96dd17 commit d4691eb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
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 %>

0 comments on commit d4691eb

Please sign in to comment.