SimpleForm + ClientSideValidations + Bootstrap - Die Validierung findet nicht auf dem Formular statt. Alle Eingaben werden akzeptiert
Ich verwende die Edelsteine SimpleForm, ClientSideValidations und ClientSideValidations-SimpleForm in einer RoR-Anwendung. Ich kann das Formular schön in das Modal rendern, aber wenn die Eingabe den Fokus verliert, erfolgt keine Validierung und das Formular wird gesendet. Beachten Sie auch, dass ich versucht habe, das hier gefundene Update zu verwenden:http://www.ddarrensmith.com/blog/2012/05/17/ruby-on-rails-client-side-validation-with-validation-helpers-and-twitter-bootstrap/
Segment der Ansicht mit dem Formular:
<div class='modal hide' id='New_Discrep' tabindex="-1" role='dialog' aria-labelledby="#New_Discrep_Label" aria-hidden='true'>
<div class="modal-header">
<button type='button' class='close' data-dismiss='modal' aria- hidden='true'>x</button>
<h3 id="New_Discrep_Label">Create Discrepancy</h3>
</div>
<%= simple_form_for @new_discrepancy, :validate => true, :url => {:controller=> 'discrepancy', :action => 'create', :device_id => @device.id} do |f| %>
<div class='modal-body'>
<%= f.input :system, :wrapper => :prepend, :label => false do %>
<%= content_tag :span, 'System', :class => 'add-on input-label' %>
<%= f.input_field :system %>
<% end %>
<%= f.input :description, :wrapper => :prepend, :label => false do %>
<%= content_tag :span, 'Description', :class => 'add-on input-label' %>
<%= f.input_field :description, :class => 'textarea' %>
<% end %>
<%= f.input :conditions, :wrapper => :prepend, :label => false do %>
<%= content_tag :span, 'Condiditions', :class => 'add-on input-label' %>
<%= f.input_field :conditions, :class => 'textarea' %>
<% end %>
<%= f.input :dirf, :wrapper => :prepend, :label => false do %>
<%= content_tag :span, 'Reference', :class => 'add-on input-label' %>
<%= f.input_field :dirf %>
<% end %>
</div>
<div class='modal-footer'>
<button type="button" class='btn', data-dismiss='modal', aria-hidden='true'>Cancel</button>
<%= f.button :submit, :class => 'btn-primary' %>
</div>
<% end %>
</div>
Mein Gemfile
gem 'rails', '3.2.1'
gem 'jquery-rails'
gem 'carrierwave'
gem 'simple_form'
gem 'client_side_validations'
gem 'client_side_validations-simple_form'
Modell
class Discrepancy < ActiveRecord::Base
STATUSES = ['Open', 'Closed', 'Rejected']
belongs_to :device
belongs_to :user
has_many :parts
has_many :updates
validates :date_entered, :presence => true
validates :status, :presence => true
validates :description, :presence => true
validates :system, :presence => true
validate :close_date
validates_inclusion_of :status, :in => STATUSES,
:message => "must be one of: #{STATUSES.join(', ')}"
end
application.js Datei
//= require jquery
//= require jquery_ujs
//= require rails.validations
//= require rails.validations.simple_form
//= require_tree .
Ich habe auch bestätigt, dass das Skript-Tag in HTML direkt unter dem Formular erstellt wird. Danke für die Hilfe!