diff --git a/app/helpers/spree/admin/base_helper.rb b/app/helpers/spree/admin/base_helper.rb index 8633968e1d..28d046d53f 100644 --- a/app/helpers/spree/admin/base_helper.rb +++ b/app/helpers/spree/admin/base_helper.rb @@ -287,6 +287,10 @@ def product_wysiwyg_editor_enabled? def taxon_wysiwyg_editor_enabled? Spree::Backend::Config[:taxon_wysiwyg_editor_enabled] end + + def number_validation_pattern + '^[0-9]*([.,][0-9]*)*$' + end end end end diff --git a/app/views/spree/admin/prices/_variant_prices.html.erb b/app/views/spree/admin/prices/_variant_prices.html.erb index a8f9382536..53461476dc 100644 --- a/app/views/spree/admin/prices/_variant_prices.html.erb +++ b/app/views/spree/admin/prices/_variant_prices.html.erb @@ -22,10 +22,10 @@ <%= variant.sku %> <%= label_tag "vp[#{variant.id}][#{code}]", code %> - <%= text_field_tag "vp[#{variant.id}][#{code}][price]", (price && price.price ? price.display_amount.money : ''), class: 'form-control' %> + <%= text_field_tag "vp[#{variant.id}][#{code}][price]", (price && price.price ? price.display_amount.money : ''), class: 'form-control', pattern: number_validation_pattern %> - <%= text_field_tag "vp[#{variant.id}][#{code}][compare_at_price]", (price && price.compare_at_price ? price.display_compare_at_amount.money : ''), class: 'form-control' %> + <%= text_field_tag "vp[#{variant.id}][#{code}][compare_at_price]", (price && price.compare_at_price ? price.display_compare_at_amount.money : ''), class: 'form-control', pattern: number_validation_pattern %> <% end %> diff --git a/app/views/spree/admin/products/_form.html.erb b/app/views/spree/admin/products/_form.html.erb index f3f70b2073..ead839c43d 100644 --- a/app/views/spree/admin/products/_form.html.erb +++ b/app/views/spree/admin/products/_form.html.erb @@ -30,12 +30,12 @@
<%= f.field_container :price do %> - <%= f.label :price, raw(Spree.t(:master_price) + required_span_tag) %> + <%= f.label :price, raw(Spree.t(:price) + required_span_tag) %>
<%= currency_symbol(current_currency) %>
- <%= f.text_field :price, value: number_to_currency(@product.amount_in(current_currency), unit: ''), class: 'form-control', disabled: (cannot? :update, @product.master.default_price) %> + <%= f.text_field :price, value: number_to_currency(@product.amount_in(current_currency), unit: ''), class: 'form-control', disabled: (cannot? :update, @product.master.default_price), pattern: number_validation_pattern %>
<%= f.error_message_on :price %> <% end %> @@ -48,7 +48,7 @@
<%= currency_symbol(current_currency) %>
- <%= f.text_field :compare_at_price, value: number_to_currency(@product.compare_at_amount_in(current_currency), unit: ''), class: 'form-control' %> + <%= f.text_field :compare_at_price, value: number_to_currency(@product.compare_at_amount_in(current_currency), unit: ''), class: 'form-control', pattern: number_validation_pattern %>
<%= f.error_message_on :compare_at_price %> <% end %> @@ -57,7 +57,7 @@
<%= f.field_container :cost_price do %> <%= f.label :cost_price, Spree.t(:cost_price) %> - <%= f.text_field :cost_price, value: number_to_currency(@product.cost_price, unit: ''), class: 'form-control' %> + <%= f.text_field :cost_price, value: number_to_currency(@product.cost_price, unit: ''), class: 'form-control', pattern: number_validation_pattern %> <%= f.error_message_on :cost_price %> <% end %>
diff --git a/app/views/spree/admin/products/new.html.erb b/app/views/spree/admin/products/new.html.erb index fb76119df3..3379fbaca8 100644 --- a/app/views/spree/admin/products/new.html.erb +++ b/app/views/spree/admin/products/new.html.erb @@ -33,12 +33,12 @@
<%= f.field_container :price do %> - <%= f.label :price, raw(Spree.t(:master_price) + required_span_tag) %> + <%= f.label :price, raw(Spree.t(:price) + required_span_tag) %>
<%= currency_symbol(current_currency) %>
- <%= f.text_field :price, value: number_to_currency(@product.price, unit: ''), class: 'form-control', required: :required %> + <%= f.text_field :price, value: number_to_currency(@product.price, unit: ''), class: 'form-control', required: :required, pattern: number_validation_pattern %>
<%= f.error_message_on :price %> <% end %>