Change phoenix generator form from input to textarea

I used the Phoenix generator to create a table and the accompanying HTML forms.
The form inputs are input and I want to change one of them to textarea.

The form template the generator gives me is this:

<.simple_form :let={f} for={@changeset} action={@action}>
  <.error :if={@changeset.action}>
    Oops, something went wrong! Please check the errors below.
  </.error>
  <.input field={f[:name]} type="text" label="Name" />
  <.input field={f[:version]} type="text" label="Version" />
  <.input field={f[:owner]} type="text" label="Owner" />
  <.input field={f[:note]} type="text" label="Note" />
  <.input field={f[:developer]} type="text" label="Developer" />
  <.input field={f[:status]} type="text" label="Status" />
  <.input field={f[:url]} type="text" label="Url" />
  <:actions>
    <.button>Save Test bed</.button>
  </:actions>
</.simple_form>

If I try to change one of those inputs to textarea I get an error. Example:


  <.textarea field={f[:note]} type="text" label="Note" />

How do I change them without error?

Hi @wktdev please always provide any errors that you get.

EDIT: Based on my read of the core components you should be doing:

  <.input field={f[:note]} type="textarea" label="Note" />
3 Likes

Thanks, and noted.

Can you direct me to where I can read about the core components? I can’t find anything about <.input>. For instance, how are people supposed to know what the various possible values for the type attribute are? “textarea” is not a legal type attribute for an html input element, but it works with the input function.

Also, is there something to create a datetime select, e.g.:

<%= datetime_select f, :ends_at %>

perhaps:

<.datetime >

??

Core components are defined in your application code so assuming you’re using the generators, take a look at the inline docs in your core_components.ex file.

Regarding support for "textarea", it’s added via a custom functionhead:

From a while back, here’s an example of extending the .input core component to support radio buttons.

2 Likes

Okay, I see “core components” mentioned everywhere, but there is nothing in the docs about them. In my Phoenix app, I just found the file:

auction_web/lib/auction_web/components/core_components.ex

That’s where things like <.simple_form> and <.input> come from.

The Phoenix.Component docs should allow me to figure out how the functions in core_components.ex work.