javascript - Rails 4 - JS for dependent fields with simple form -
i trying make app in rails 4.
i using simple form forms , have tried use gem 'dependent-fields-rails' hide or show subset questions based on form field of primary question.
i'm getting stuck.
i have added gems gem file for:
gem 'dependent-fields-rails' gem 'underscore-rails'
i have updated application.js to:
//= require dependent-fields //= require underscore
i have form has:
<%= f.simple_fields_for :project_date |pdf| %> <%= pdf.error_notification %> <div class="form-inputs"> <%= pdf.input :student_project, as: :radio_buttons, :label => "is project in students may participate?", autofocus: true %> <div class="js-dependent-fields" data-radio-name="project_date[student_project]" data-radio-value="true"> <%= pdf.input :course_project, as: :radio_buttons, :label => "is project students complete credit towards course assessment?" %> <%= pdf.input :recurring_project, as: :radio_buttons, :label => "is project offered on recurring basis?" %> <%= pdf.input :frequency, :label => "how project repeated?", :collection => ["no current plans repeat project", "each semester", "each year"] %> </div> <div class='row'> <div class="col-md-4"> <%= pdf.input :start_date, :as => :date_picker, :label => "when want started?" %> </div> <div class="col-md-4"> <%= pdf.input :completion_date, :as => :date_picker, :label => "when expect finish?" %> </div> <div class="col-md-4"> <%= pdf.input :eoi, :as => :date_picker, :label => 'when expressions of interest due?' %> </div> </div> </div> <% end %> <script type="text/javascript"> $('.datetimepicker').datetimepicker(); </script> <script> $(document).ready(function() { dependentfields.bind() }); </script>
i don't know javascript.
i"m not sure if final script paragraph necessary or if gem puts code you. i'm not sure if it's supposed expressed inside script tags , don't know how give effect requirement (which set out on gem page dependent-fields):
"be sure include underscorejs , jquery in page."
how include underscorejs , jquery in page? have them in gem file. enough or else required make work?
currently, when try form, nothing hidden. have tried swapping true value 'yes' doesnt make difference either.
<div class="js-dependent-fields" data-radio-name="project_date[student_project]" data-radio-value="true"> <div class="js-dependent-fields" data-radio-name="project_date[student_project]" data-radio-value="yes">
can see i've gone wrong?
i think jumping collection
attribute when define radio button.
if @ documentation example, see use collection
define values of radio button. use 1 of values defined set data-radio-value
attribute.
try , let me know:
<div class="form-inputs"> <%= pdf.input :student_project, as: :radio_buttons, autofocus: true, :label => "is project?", :collection => ['yes', 'no'] %> <div class="js-dependent-fields" data-radio-value='yes' data-radio-name="project_date[student_project]"> ... </div> </div>
update
if @ this example project, application.js file includes required libraries in different order you. error.
note requiring libraries in way:
//= require dependent-fields //= require underscore
while example project require libraries in way:
//= require underscore //= require dependent-fields
hope help!
Comments
Post a Comment