simple_form: specify id of text field

时光总嘲笑我的痴心妄想 提交于 2019-12-06 06:09:13

问题


I've got the simple simple_form below. I'm trying to make the ID of the input field be 'my-id', but the solution below doesn't work (the id is 'comment_body'). How can I specify the id for that input field?

= simple_form_for(@comment) do |f|
    = f.input :body, as: :string, html: {id: "my-id"}
    = f.button :submit

I've also tried

    = f.input :body, as: :string, id: "my-id"

to no avail.


回答1:


:input_html works, not :html.

 = f.input :body, as: :string, input_html: {id: "my-id"}



回答2:


The way to add an ID to a simpleform input field has changed since this question was first answered.

The latest syntax (version 3.2.0) would be what the op tried:

 = f.input :body, as: :string, id: "my-id"

I thought I'd add an update to this question as it comes near to the top of Google when searching for 'simpleform id'.



来源:https://stackoverflow.com/questions/11572989/simple-form-specify-id-of-text-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!