【发布时间】:2016-02-24 10:12:17
【问题描述】:
我有 AJAX 来创建新项目并在我的视图中更新它们。
当我创建一个新模型时,我的模型验证阻止它被保存或提交。
但是,当我更新现有字段时,它只会停止保存它,但它会使用“新”数据呈现 ajax 更新表单,给人的印象是它正在被保存。
当我之后刷新时,我看到更改已回滚。但这只是我想要的行为的一半。
我需要禁用提交按钮。我怎样才能做到这一点?
我的表单样式如下:
<%= f.text_field :name, required: true, class: "mdl-textfield__input" %>
我在模型中的验证看起来像这样:
validates_presence_of :name
我的edit.js.erb
$("#education_<%=@employee_education.id%>").replaceWith("<%= j render('new_employee_education_form')%>");
我的 update.js.erb
$("#edit_employeeeducation_<%= @employee_education.id %>").replaceWith('<%= j render partial: "employeeeducation", locals: {employee_education: @employee_education} %>');
【问题讨论】:
-
基本上你没有处理错误,如果有错误,你应该再次呈现表单,而不是显示部分输出数据。
标签: ruby-on-rails ajax validation