Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails上的简单表单-如何在提交后显示错误验证_Ruby On Rails_Simple Form_Simple Form For - Fatal编程技术网

Ruby on rails Rails上的简单表单-如何在提交后显示错误验证

Ruby on rails Rails上的简单表单-如何在提交后显示错误验证,ruby-on-rails,simple-form,simple-form-for,Ruby On Rails,Simple Form,Simple Form For,我试图只在用户单击提交按钮时显示表单中的错误,但目前,它在用户单击提交按钮之前显示所有错误。如何仅在用户提交表单时显示错误 我在Rails中使用简单表单 这是我的简单表格: <div class="col-md-10 col-lg-8 col-xl-5 col-md-offset-4 mx-auto"> <%= simple_form_for @customer, url: customers_path, method: :post do |f| %> <%

我试图只在用户单击提交按钮时显示表单中的错误,但目前,它在用户单击提交按钮之前显示所有错误。如何仅在用户提交表单时显示错误

我在Rails中使用简单表单

这是我的简单表格:

<div class="col-md-10 col-lg-8 col-xl-5 col-md-offset-4 mx-auto">
  <%= simple_form_for @customer, url: customers_path, method: :post do |f| %>
  <%= f.error_notification %>
  <%= f.input :first_name %>
  <%= f.input :last_name %>
  <%= f.input :email, input_html: { autocomplete: 'email' } %>
  <%= f.input :budget, collection: ["€200,000 - €299,999", "€300,000 - €399,999", "€400,000 - €499,999", "€500,000 - €649,999", "€650,000 - €799,999", "€800,000 - €1,000,000", "€1,000,000 +"] %>
  <%= f.input :comments, :as => :text, :input_html => { 'rows' => 10, 'cols' => 10 } %>
  <%= f.button :submit, "Submit", class: "btn-primary trigger mt-1" %>
  <% end %>
</div>

:text,:input_html=>{'rows'=>10,'cols'=>10}%>
以下是我的客户模型中的客户验证:

class Customer < ApplicationRecord
  validates :email, presence: true, format: { with: URI::MailTo::EMAIL_REGEXP }, uniqueness: true
  validates :first_name, presence: true, length: { minimum: 2 }
  validates :last_name, presence: true, length: { minimum: 2 }
  validates :budget, presence: true
  validates :comments, presence: true
end
class客户

谢谢

您可以像下面这样更改(第2行)的简单表单

<%= simple_form_for @customer, html: { novalidate: true }, url: customers_path, method: :post do |f| %>

说明:
通过添加,html:{novalidate:true}此选项向表单添加新的novalidate属性,指示表单跳过所有html 5验证

您可以像下面这样更改(第2行)的简单表单

<%= simple_form_for @customer, html: { novalidate: true }, url: customers_path, method: :post do |f| %>

说明:
通过添加,html:{novalidate:true}此选项向表单添加新的novalidate属性,指示表单跳过所有html 5验证

非常感谢你,我尝试了这个,但没有改变任何事情-错误仍然显示。此外,我还试图获取它,以便只有在单击“提交”按钮后才会显示错误。目前,它预先显示了如何阻止这种情况发生的任何想法?非常感谢您,我尝试了这个,但它没有改变任何事情-错误仍然显示。此外,我还试图获取它,以便只有在单击“提交”按钮后才会显示错误。目前,它预先显示了如何阻止这种情况发生的想法?