2012-08-30 199 views
2

在我的地盤,我想用不同的驗證(例如 - 在我的註冊頁面 - 我使用客戶端驗證,但在我的職位頁 - 我用標準的審定=>Rails的客戶端驗證

<% if post.errors.any? %> 
    <div id="errorExplanation"> 
     <h2><%= pluralize(post.errors.count, "error") %> prohibited this post from being saved:</h2> 
     <ul> 
      <% post.errors.full_messages.each do |msg| %> 
       <li><%= msg %></li> 
      <% end %> 
     </ul> 
    </div> 
    <% end %> 

但是當我提出我的空單 - 我看到了標準的驗證和客戶端驗證enter image description here

它本身增加了「不能爲空」(我的圖片 - 場下有標題和正文)

我認爲這使得config/initializers/client_side_validation.rb

ActionView::Base.field_error_proc = Proc.new do |html_tag, instance| 
    unless html_tag =~ /^<label/ 
    %{<div class="field_with_errors">#{html_tag}<label for="#{instance.send(:tag_id)}" class="message">#{instance.error_message.first}</label></div>}.html_safe 
    else 
    %{<div class="field_with_errors">#{html_tag}</div>}.html_safe 
    end 
end 

我該如何關閉它,僅限於這種形式?

回答

0

我認爲你的腳本客戶端驗證不起作用導致表單正在提交。如果你想要一個表單不被驗證在客戶端,':驗證'參數在你的表單中爲false。

<%= book.fields_for :pages, :validate => false do |page| -%> 
+0

沒有,這是我的第一個想法,但是當我點擊領域 - 沒有什麼變化......但是當我提交表單 - 然後創建此