我正在使用wicked创建一个多步骤向导。我想使用 AJAX,这样我就可以逐步浏览表单而无需重新加载页面。我在网上找不到有关如何执行此操作的任何信息。有没有人这样做过?
问问题
563 次
1 回答
1
我可能有点晚了,但我只是在做一个使用这些相同功能的项目,所以如果有其他人想知道同样的事情,希望这可能会有所帮助。
一般来说,最好像设置普通 HTML 向导一样设置 Wicked:
应用程序/控制器/set_up_positions_controller.rb
class SetUpPositionController < ApplicationController
include Wicked::Wizard
steps :appointment_settings, :lab_settings
def show
case step
when :appointment_settings
when :lab_settings
end
render_wizard
end
def update
case step
when :appointment_settings
#LOGIC
when :lab_settings
#LOGIC
end
render_wizard @position
end
end
从这里开始,诀窍是为每个步骤创建一个 step_name.js.erb 和一个 _step_name.html.erb 文件。IE。
app/views/set_up_positions/appointment_settings.js.erb
$('#clinics-content').html('<%= j render "clinic_management/set_up_position/appointment_settings" %>');
app/views/set_up_positions/_appointment_settings.html.erb
<%= simple_form_for [:clinic_management, @clinic, @position], url: wizard_path, method: :put, remote: true do |f| %>
<%= f.input :bill_authorization, collection: bill_authorization_options %>
#etc etc
<% end%>
您可能希望在 JS 文件中添加一些错误消息(现在它调用相同的 JS 并在字段名称下呈现错误,在这种情况下,这可能是您想要的,也可能不是您想要的)。
根据您的用例,为此类事物使用其中一个 JS 框架(如 steps.js)也可能更容易。我没有因为我比 JS 更了解 ruby,但对于其他人来说,这也是一种选择。
于 2017-07-06T01:09:20.430 回答