From d4691eba14ebcb8b94650f80e61a5e64c3e33030 Mon Sep 17 00:00:00 2001 From: rahul2103 Date: Tue, 19 Nov 2024 18:02:53 +0530 Subject: [PATCH] prototype populate bug fix --- .../spree/admin/prototypes/_prototypes.html.erb | 2 +- app/views/spree/admin/prototypes/select.js.erb | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/views/spree/admin/prototypes/_prototypes.html.erb b/app/views/spree/admin/prototypes/_prototypes.html.erb index 4eff569c88..d6422b1cab 100644 --- a/app/views/spree/admin/prototypes/_prototypes.html.erb +++ b/app/views/spree/admin/prototypes/_prototypes.html.erb @@ -8,7 +8,7 @@ <% @prototypes.each do |prototype| %> - + <%= prototype.name %> diff --git a/app/views/spree/admin/prototypes/select.js.erb b/app/views/spree/admin/prototypes/select.js.erb index f31df83002..94fb55cead 100644 --- a/app/views/spree/admin/prototypes/select.js.erb +++ b/app/views/spree/admin/prototypes/select.js.erb @@ -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 %>