title: Phoenix Form Field For Array Model Data Type
body: <p>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.</p>
  <p>Here is an example field from the model:
  <code>field :grateful, {:array, :string}</code></p>
  <p>I've tried generating the fields like this:</p>
  <pre><code>&lt;%= inputs_for f, :grateful, fn fp -&gt; %&gt;
     &lt;%= text_input fp, :grateful %&gt;
  &lt;% end %&gt;
  </code></pre>
  <p>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</p>
  <p>If I generate the field like this: <code>&lt;%= text_input fp, :grateful %&gt;</code> it generates a form field with a name of: <code>daily_post[grateful]</code> which actually won't work. I would need <code>daily_post[grateful][]</code>.</p>
  <p>The code below works, but loading the data after saving does not work. All array values are merged into one input field.</p>
  <pre><code>  &lt;div class=&quot;form-group&quot; id=&quot;grateful-group&quot;&gt;
      &lt;%= label f, :grateful, class: &quot;control-label&quot; %&gt;
        &lt;%= text_input f, :grateful, name: &quot;daily_post[grateful][]&quot; %&gt;
      &lt;%= error_tag f, :grateful %&gt;
      &lt;input type=&quot;button&quot; class=&quot;btn btn-success&quot; id=&quot;add-grateful&quot; value=&quot;add&quot; /&gt;
      &lt;script&gt;
        window.onload = () =&gt; {
          $('#add-grateful').click((e) =&gt; {
            $('&lt;input type=&quot;text&quot; name=&quot;daily_post[grateful][]&quot; /&gt;').appendTo(&quot;#grateful-group&quot;);
          })
        }
      &lt;/script&gt;
    &lt;/div&gt;
  </code></pre>
  <p>How can I properly work with the array datatype in phoenix?</p>
  <p>Thanks!</p>