Improve delivery form validation

This commit is contained in:
Julius 2013-06-19 11:21:55 +02:00
parent 0b81ba97b9
commit bf32e72414
4 changed files with 23 additions and 7 deletions

View file

@ -9,7 +9,7 @@ class Delivery < ActiveRecord::Base
scope :recent, :order => 'created_at DESC', :limit => 10
validates_presence_of :supplier_id
validates_presence_of :supplier_id, :delivered_on
accepts_nested_attributes_for :stock_changes, :allow_destroy => :true

View file

@ -79,6 +79,7 @@
.span6
%h2= t '.title_fill_quantities'
<!-- = f.inspect -->
%table.table.table-condensed#stock_changes
%thead
%tr
@ -92,14 +93,14 @@
-# see also the partial 'stock_change' which is used for AJAX updates!
-# see also the partial 'stock_change' which is used for AJAX updates!
-# see also the partial 'stock_change' which is used for AJAX updates!
= f.fields_for :stock_changes do |stock_change_form|
= f.simple_fields_for :stock_changes do |stock_change_form|
- stock_change = stock_change_form.object
%tr{:id => "stock_change_stock_article_#{stock_change.stock_article.id}", :data => {:id => stock_change.stock_article.id}}
%td.sort-by-name
= stock_change_form.hidden_field :stock_article_id
= stock_change_form.association :stock_article, :as => :hidden
%span.stock_article_name= stock_change.stock_article.name
%td.numeric.price-per-unit #{number_to_currency stock_change.stock_article.price}/#{stock_change.stock_article.unit}
%td= stock_change_form.text_field :quantity, :size => 5, :autocomplete => 'off'
%td= stock_change_form.input :quantity, :wrapper => :intable, :input_html => {:class => 'stock-change-quantity', :autocomplete => :off}
%td
= stock_change_form.hidden_field :_destroy
= link_to t('.remove_article'), "#", :class => 'destroy_stock_change btn btn-small'

View file

@ -1,12 +1,12 @@
-# see also the partial 'form' which is used for existing stock_changes when loading the edit!
-# see also the partial 'form' which is used for existing stock_changes when loading the edit!
-# see also the partial 'form' which is used for existing stock_changes when loading the edit!
= fields_for "delivery[new_stock_changes][]", stock_change, validate: true do |f|
= simple_fields_for "delivery[new_stock_changes][]", stock_change, validate: true do |f|
- f.object.quantity = '' if 0 == f.object.quantity
%tr{:id => "stock_change_stock_article_#{stock_change.stock_article.id}", :data => {:id => stock_change.stock_article.id}}
%td.sort-by-name
= f.hidden_field :stock_article_id
= f.association :stock_article, :as => :hidden
%span.stock_article_name= stock_change.stock_article.name
%td.numeric.price-per-unit #{number_to_currency stock_change.stock_article.price}/#{stock_change.stock_article.unit}
%td= f.text_field :quantity, :size => 4, :autocomplete => 'off', :required => true, :class => 'stock-change-quantity'
%td= f.input :quantity, :wrapper => :intable, :input_html => {:class => 'stock-change-quantity', :autocomplete => :off}
%td= link_to t('.remove_article'), "#", :class => 'remove_new_stock_change btn btn-small'

View file

@ -45,6 +45,21 @@ SimpleForm.setup do |config|
b.use :error, :wrap_with => { :tag => :span, :class => :error }
end
config.wrappers :intable, :class => 'control-group',
:error_class => :error do |b|
b.use :html5
b.use :placeholder
b.optional :maxlength
b.optional :pattern
b.optional :min_max
b.optional :readonly
b.use :input
b.use :hint
b.use :error, :wrap_with => { :tag => :span, :class => 'help-inline' }
end
# The default wrapper to be used by the FormBuilder.
config.default_wrapper = :default