I'm using the amazing Phoenix Web Framework and trying to figure out how to create the form field(s) for a model with an array field.
Here is an example field from the model: field :grateful, {:array, :string}
I've tried generating the fields like this:
<%= inputs_for f, :grateful, fn fp -> %>
<%= text_input fp, :grateful %>
<% end %>
But I get this error: could not generate inputs for :grateful from Motivation.DailyPost. Check the field exists and it is one of embeds_one, embeds_many, has_one, has_many, belongs_to or many_to_many
If I generate the field like this: <%= text_input fp, :grateful %> it generates a form field with a name of: daily_post[grateful] which actually won't work. I would need daily_post[grateful][].
How can I generate a form element for a model with an array datatype? I keep finding answers for nested form fields and relations, but this is a bit different and those solutions do not work.
FYI: This is cross posted on stackoverflow so you can answer the question there if you want to get the points. Here is a link: http://stackoverflow.com/questions/41404526/phoenix-form-field-for-array-model-data-type
Thanks!
` <div class="form-group" id="grateful-group"><%= label f, :grateful, class: "control-label" %><%= text_input f, :grateful, name: "daily_post[grateful][]" %><%= error_tag f, :grateful %><input type="button" class="btn btn-success" id="add-grateful" value="add" /><script>window.onload = () => {$('#add-grateful').click((e) => {$('<input type="text" name="daily_post[grateful][]" />').appendTo("#grateful-group");})}</script></div>`