PhoenixMTM v1.0.0 PhoenixMTM.Mappers View Source

A collection of commonly used mappers for the collection_checkboxes helper.

To use, pass a capture of the mapping function you wish to use to the collection_checkboxes helper.

Example

<%= PhoenixMTM.Helpers.collection_checkboxes f, :tags,
      Enum.map(@tags, &({&1.name, &1.id})),
      selected: Enum.map(f.data.tags, &(&1.id)),
      mapper: &PhoenixMTM.Mappers.nested/6

Using Custom Mappers

If you want to make your own custom mapper, you can optionally use PhoenixMTM.Mappers and bring in some of the Phoenix tag helpers.

This is not required, as you can manually include which ever imports you want.

Link to this section Summary

Functions

Checkbox input and label returned as a label with the checkbox and label text nested within

Checkbox input and label returned as a label with the checkbox and label text nested within. The label text is not escaped in any way

Checkbox input and label returned as a 2 element list - the default

Link to this section Functions

Link to this function

nested(form, field, input_opts, label_content, label_opts, opts) View Source

Checkbox input and label returned as a label with the checkbox and label text nested within.

Example Output

<label for="checkbox_1">
  <input type="checkbox" value="1" name="checkbox_1">
  1
</label>
Link to this function

unsafe_nested(form, field, input_opts, label_content, label_opts, opts) View Source

Checkbox input and label returned as a label with the checkbox and label text nested within. The label text is not escaped in any way.

If you are displaying labels that might be provided by untrusted users, you absolutely do not want to use this mapper.

This mapper will be deprecated at a later date. If you wish to keep this functionality, copy it to your own custom mapper module.

Example Output

<label for="checkbox_1">
  <input type="checkbox" value="1" name="checkbox_1">
  1
</label>
Link to this function

unwrapped(form, field, input_opts, label_content, label_opts, opts) View Source

Checkbox input and label returned as a 2 element list - the default.

Example Output

<input type="checkbox" value="1" name="checkbox_1">
<label for="checkbox_1">1</label>