diff --git a/backend/app/views/spree/admin/products/_form.html.erb b/backend/app/views/spree/admin/products/_form.html.erb index 478414b7d15..4f8be06bb0f 100644 --- a/backend/app/views/spree/admin/products/_form.html.erb +++ b/backend/app/views/spree/admin/products/_form.html.erb @@ -13,8 +13,8 @@
<%= f.field_container :slug do %> - <%= f.label :slug, class: 'required' %> - <%= f.text_field :slug, class: 'fullwidth title', required: true %> + <%= f.label :slug, class: ('required' if !f.object.new_record?) %> + <%= f.text_field :slug, class: 'fullwidth title', required: !f.object.new_record?, disabled: f.object.new_record? %> <%= f.error_message_on :slug %> <% end %>
@@ -122,9 +122,9 @@
<%= f.field_container :shipping_categories do %> - <%= f.label :shipping_category_id, Spree::ShippingCategory.model_name.human %> + <%= f.label :shipping_category_id, Spree::ShippingCategory.model_name.human, class: 'required' %> <%= f.field_hint :shipping_category %> - <%= f.collection_select(:shipping_category_id, @shipping_categories, :id, :name, { include_blank: t('spree.match_choices.none') }, { class: 'custom-select' }) %> + <%= f.collection_select(:shipping_category_id, @shipping_categories, :id, :name, { include_blank: t('spree.match_choices.none') }, { class: 'custom-select' , required: true}) %> <%= f.error_message_on :shipping_category %> <% end %>
diff --git a/backend/app/views/spree/admin/products/index.html.erb b/backend/app/views/spree/admin/products/index.html.erb index 3c27ba0b617..3920be56187 100644 --- a/backend/app/views/spree/admin/products/index.html.erb +++ b/backend/app/views/spree/admin/products/index.html.erb @@ -3,8 +3,8 @@ <% admin_breadcrumb(plural_resource_name(Spree::Product)) %> <% content_for :page_actions do %> -
  • + <%= button_link_to t('spree.new_product'), new_object_url %>
  • <% end if can?(:create, Spree::Product) %> diff --git a/backend/app/views/spree/admin/products/new.html.erb b/backend/app/views/spree/admin/products/new.html.erb index 9acd40d9c39..44f36c06662 100644 --- a/backend/app/views/spree/admin/products/new.html.erb +++ b/backend/app/views/spree/admin/products/new.html.erb @@ -1,68 +1,14 @@ +<% admin_breadcrumb link_to(plural_resource_name(Spree::Product), spree.admin_products_path) %> +<% admin_breadcrumb t('spree.new_product') %> + <%= render partial: 'spree/shared/error_messages', locals: { target: @product } %> <%= form_for [:admin, @product], method: :post, url: admin_products_path, html: { multipart: true } do |f| %> -
    - <%= t('spree.new_product') %> - <%= f.field_container :name do %> - <%= f.label :name, class: 'required' %>
    - <%= f.text_field :name, class: 'fullwidth title', required: true %> - <%= f.error_message_on :name %> - <% end %> - -
    - <% unless @product.has_variants? %> -
    - <%= f.field_container :sku do %> - <%= f.label :sku, t('spree.sku') %>
    - <%= f.text_field :sku, size: 16, class: 'fullwidth' %> - <%= f.error_message_on :sku %> - <% end %> -
    - <% end %> - -
    - <%= f.field_container :price do %> - <%= f.label :price, class: 'required' %>
    - <%= f.text_field :price, value: number_to_currency(@product.price, unit: ''), class: 'fullwidth', required: true %> - <%= f.error_message_on :price %> - <% end %> -
    - -
    - <%= f.field_container :available_on do %> - <%= f.label :available_on %> - <%= f.error_message_on :available_on %> - <%= f.text_field :available_on, class: 'datepicker fullwidth' %> - <% end %> -
    - -
    - -
    -
    - <%= f.field_container :shipping_category do %> - <%= f.label :shipping_category_id, Spree::ShippingCategory. - model_name.human, class: 'required' %> - <%= f.field_hint :shipping_category %>
    - <%= f.collection_select(:shipping_category_id, @shipping_categories, :id, :name, { include_blank: t('spree.match_choices.none') }, { class: 'custom-select fullwidth' }) %> - <%= f.error_message_on :shipping_category_id %> - <% end %> -
    - -
    - <%= f.field_container :tax_category do %> - <%= f.label :tax_category_id, Spree::TaxCategory.model_name.human %> - <%= f.field_hint :tax_category %> - <%= f.collection_select(:tax_category_id, @tax_categories, :id, :name, { include_blank: t('spree.match_choices.none') }, { class: 'custom-select fullwidth' }) %> - <%= f.error_message_on :tax_category %> - <% end %> -
    -
    + <%= render partial: 'form', locals: { f: f } %> <%= render partial: 'spree/admin/shared/new_resource_links' %> -
    <% end %> diff --git a/backend/app/views/spree/admin/products/new.js.erb b/backend/app/views/spree/admin/products/new.js.erb deleted file mode 100644 index c51b8081b89..00000000000 --- a/backend/app/views/spree/admin/products/new.js.erb +++ /dev/null @@ -1,4 +0,0 @@ -$("#new_product_wrapper").html('<%= escape_javascript(render template: "spree/admin/products/new", formats: [:html], handlers: [:erb]) %>'); -handle_date_picker_fields(); -$("#table-filter").hide(); -$("#admin_new_product").parent().hide(); diff --git a/backend/spec/features/admin/products/products_spec.rb b/backend/spec/features/admin/products/products_spec.rb index 6fa49c97af0..fe26a583a4d 100644 --- a/backend/spec/features/admin/products/products_spec.rb +++ b/backend/spec/features/admin/products/products_spec.rb @@ -156,10 +156,7 @@ def build_option_type_with_values(name, values) before(:each) do @shipping_category = create(:shipping_category) click_nav "Products" - click_link "admin_new_product" - within('#new_product') do - expect(page).to have_content("SKU") - end + click_on "New Product" end it "should allow an admin to create a new product", js: true do @@ -174,7 +171,7 @@ def build_option_type_with_values(name, values) expect(page).to have_content("successfully updated!") end - it "should show validation errors", js: true do + it "should show validation errors", js: false do fill_in "product_name", with: "Baseball Cap" fill_in "product_sku", with: "B100" fill_in "product_price", with: "100"