Skip to content

Commit

Permalink
form submit, errors
Browse files Browse the repository at this point in the history
  • Loading branch information
michelson committed Jul 14, 2024
1 parent 05927c1 commit a9c350c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 16 deletions.
36 changes: 24 additions & 12 deletions app/views/products/_form.erb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@

<% # render "variant_form_section", form: form %>
<div class="border p-4 my-4">
<div class="border border-muted rounded-lg p-4 my-4">
<h3 class="text-lg">Shipping</h3>
<div>
Expand All @@ -117,22 +117,22 @@
<span>days of being placed</span>
</div>
<div>
<%= form.number_field :shipping_days, label: "Orders ship out within", class: "mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" %>
<span class="mt-1 text-sm text-gray-500">days of being placed</span>
</div>
<div>
<%= form.date_field :shipping_begins_on, label: "Begins shipping on", class: "mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" %>
</div>
<div data-controller="nested-form" class="py-6 sm:col-span-6">
<template data-nested-form-target="template">
<%= form.fields_for :product_shippings, ProductShipping.new, child_index: 'NEW_RECORD' do |ff| %>
<%= render "shipping_fields", form: ff %>
<% end %>
</template>
<div>
<%= form.number_field :shipping_days, label: "Orders ship out within", class: "mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" %>
<span class="mt-1 text-sm text-gray-500">days of being placed</span>
</div>
<div>
<%= form.date_field :shipping_begins_on, label: "Begins shipping on", class: "mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" %>
</div>
<!--<div>
<h3 class="text-lg font-medium text-gray-900">Shipping Prices</h3>
<div>
Expand All @@ -158,8 +158,20 @@
</div>


<div class="py-2">
<%= form.submit %>
<div class="py-2 fixed bottom-[65px] w-full bg-muted left-0 border-t border-muted">

<div class="flex space-x-2 items-center p-6">

<%= form.submit %>
<% if form.object.errors.any? %>
<div class="py-3">
<p class="text-danger text-red-500 text-2xl">Errors Found</p>
<%= form.object.errors.full_messages.join(" ") %>
</div>
<% end %>

</div>
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion app/views/products/_product_images.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="nested-fields border mt-6 p-4"
<div class="nested-fields border mt-6 p-4 border-muted rounded-lg"
data-new-record="<%= form.object.new_record? %>">

<div class="flex space-x-2">
Expand Down
12 changes: 9 additions & 3 deletions app/views/products/_shipping_fields.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="nested-fields border mt-6 p-4"
<div class="nested-fields mt-6 p-4 bg-muted rounded-lg"
data-new-record="<%= form.object.new_record? %>">

<div class="flex items-center space-x-2">
Expand All @@ -7,11 +7,17 @@
<%= form.country_select :country,
disabled: form.object.is_default?,
priority_countries: ["CL", "AR", "PE", "BO", "CO", "MX", "US", "BR", "ES", "FR", "GR"],
except: %w[AS CX CC CU HM IR KP MH FM NF MP PW SD SY UM VI]
except: %w[AS CX CC CU HM IR KP MH FM NF MP PW SD SY UM VI]
%>

<div class="mt-1 text-xs text-gray-500 dark:text-gray-100">
<div class="text-gray-500 text-xs">
Shipping country
</div>
</div>
</div>

<%= form.number_field :base_cost, step: 0.01, label: "USD for 1 unit" %>
<%= form.number_field :base_cost, step: 0.01, label: "USD for 1 unit", hint: "Base cost" %>
<%= form.number_field :additional_cost, step: 0.01, hint: "USD more per additional unit" %>
</div>
Expand Down

0 comments on commit a9c350c

Please sign in to comment.