I'm David Weirich, a software developer based out of Long Beach, CA. Hire me to work on your next project through my company Activated Apps LLC.

Elixir: Using append and prepend options with inputs_for

The inputs_for method comes with two options for rendering the page with new elements as part of the collection you’re modifying (if it is a collection). For example, if you’re creating a to-do list that has a number of items, you could use the options like so:

<%= inputs_for f, :items, [append: [%App.Lists.Item{}], fn i -> %>
<%= text_input i, :description %>
<% end %>

If we already have items in the collection, inputs_for will iterate and fill the fields with the appropriate values, then append the new entry to the end, or in the case of prepend it will add the new entry to the beginning of the collection.

I'm David Weirich, a software developer based out of Long Beach, CA. Hire me to work on your next project through my company Activated Apps LLC.