Remove form inputs based on parameters.
Cocoon is listing previously added relationships in my edit form like it is supposed to but I am wondering what is the correct way to hide inputs conditionally. For example, each cocoon field has task_id. I want cocoon to bypass rendering inputs with task_id of 2. I am thinking I could find the inputs with javascript, and hide the parent divs, but I am wondering if there is a way to do it without javascript?
You can do something simple like
= f.fields_for :tasks do |task_form|
- if task_form.object.task_id != 2
= render 'task_fields', f: task_form
This will only render the nested fields if the task_id is different from 2.
For clarity: if f is your form-object, f.object will point to the object for which the form is built (so here your nested item)
Thanks Nathan!
No problem :+1: :smile: