Restrict Phoenix Component Attr Values
If you want to limit the permissible values of a Phoenix Component attribute, you can use the values
keyword list option when you call attr/3
. Here's is an example that restricts which atoms are being passed to the component:
use MyApp.Component
attr :acceptable_color, :atom, values: [:green, :blue]
if you were to pass any atom other than :green
or :blue
to this component, the compiler will warn you.