Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple Form - Rails 4 - editing

I am trying to use simple form with my rails 4 app.

I have a project model, which has a scope model. Scope belongs to project. I have a third model, called participant, which belongs to scope. Scope accepts nested attributes for participant and project accepts nested attributes for scope.

When I create a new project, my form has partials which are nested forms for each of scope and participant. In my scope form, I ask whether this project involves participants. If the answer is true, I use JS form helper to show a hidden partial which contains the participant form.

If, after creating the project, I want to edit it, the edit function returns me to the project form, which shows the checkbox for participant (as true), but hides the participant form.

My question is, if the participant checkbox is checked as true, then the participant form nested in the project form should be revealed. My JS form helper hides this form until the box is checked as true, and this works fine in the create mode, but I need to un check the participant box in the scope form and re-check it in order to reveal the participant form - so that i can edit those fields.

Do you know how to reveal the participant form if the scope question asking about participation is true without unchecking and rechecking the form?

My code is as follows:

In my JS form helper, I have (which hides the participant nested form unless the scope question asking if participation is sought is true):

$(document).on 'change', '#' + inString +  '_scope_attributes_if_participant', ()->
  if $('#' + inString +  '_scope_attributes_if_participant').is(':checked')
    $('#participationrequest').show()
  else
    $('#participationrequest').hide()

In my scope form, I have:

    <%= s_all.input :if_participant, :as => :boolean, :label => false, inline_label: 'Public participants or volunteers' %>

Thank you

like image 927
Mel Avatar asked Jun 02 '15 05:06

Mel


1 Answers

if $('#' + inString +  '_scope_attributes_if_participant').is(':checked')
  $('#participationrequest').show()
else
  $('#participationrequest').hide()
$(document).on 'change', '#' + inString +  '_scope_attributes_if_participant', ()->
  if $('#' + inString +  '_scope_attributes_if_participant').is(':checked')
    $('#participationrequest').show()
  else
    $('#participationrequest').hide()
like image 191
Mel Avatar answered Nov 20 '22 06:11

Mel