I'm trying to create a two stage user on boarding process. First users enter in the business they are in and then add a description. When they click submit, I want to hide that part of the form and show the "Create Account fields"
I'm using Devise and I've created the forms as a nested attribute. I've written the JavaScript code so that it hides the first part of the form but when I enter text in the field, it doesn't work. Here's the code:
application.js
$(document).ready(function () {
$("#hide").click(function(){
$(".submit").hide("fast");
});
$("#hide").click(function(){
$("#next").removeClass("hide");
});
});
devise/registrations/new.html.erb
<div class="box">
<% resource.submissions.build if resource.submissions.empty? %>
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<%= f.fields_for :submissions do |submission_form| %>
<div class="submit">
<div class="form-group">
<%= submission_form.label :business, "What industry are you in?" %>
<%= submission_form.text_field :business, class: "form-control", :autofocus => true %>
</div>
<div class="form-group">
<%= submission_form.label :description, "Describe your business. Please include a name, URL, and business model." %>
<br><br>
<%= submission_form.text_area :description, class: "form-control" %>
</div>
</div>
<% end %>
<div class="btn btn-lg btn-primary submit" id="hide">Next</div>
<br>
<div class="hide" id="next">
<h2>Create your account.</h2>
<div class="from-group">
<%= f.label :name %><br />
<%= f.text_field :name, class: "form-control", :autofocus => true %>
</div>
<div class="form-group">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: false, class: "form-control" %>
</div>
<div class="form-group">
<%= f.label :password %>
<% if @validatable %>
<em>(<%= @minimum_password_length %> characters minimum)</em>
<% end %><br />
<%= f.password_field :password, autocomplete: "off", class: "form-control" %>
</div>
<div class="form-group">
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation, autocomplete: "off", class: "form-control" %>
</div>
<div class="form-group">
<%= f.submit "Sign up", class: "btn btn-primary" %>
</div>
</div>
<% end %>
<%= render "devise/shared/links" %>
</div>
I'm having a hard time debugging this as I'm pretty new to JavaScript and Rails. This is my first time writing custom JavaScript in a Rails app so I'm sure I'm missing something simple. Any ideas on what is causing this and how to fix it?