How to generate an input in phoenix forms without id or name fields?

How to generate a datetime_select without an :id or a :name?

When I use

<%= datetime_select nil, nil %>

it still generates a name and an id

1 Like

Hi @alsaraha can you elaborate why you are trying to do this? The HTML spec requires that all inputs have names, and ids are also generally a good idea. What issue are they causing you?


I need to make a template of this element and insert a new id and name

I don’t understand what this means, can you show more code?

1 Like

OK, what I am trying to achieve is dynamic field addition/removal with javascript only (i.e. without using liveview)

So, I have something like this

  <div id="datetime-template" data-name-template="datetime-input-template">
      <%= datetime_select nil, nil, name: "datetime-input-template", id: "datetime_input_template" %>

I replace the name which matches dataset.nameTemplate with a new name generated with a function that gets a suitable name for this field,

e.g.datetime-input-template[hour] is replaced with suitable-name[hour], the id is generated by converting the name into id, so I don’t really need it to be present in the “template”,

the issue is in the id because this might result in duplicated ids, all of this would be easier if I removed the id attribute all together