How to set title for text_field?

旧城冷巷雨未停 提交于 2020-01-02 07:40:11

问题


I know that is something simple, but I'm stuck. I have a several forms in my rails3 app to which I need to add tooltips, by using the tipsy. The text in tooltips should be determined in title\original-title, but I just can't figure it out, how to set it for text_field.

<%= f.text_field :what %>

gives me

<input id="name_which" name="name[which]" size="30" type="text">

and I just can't figure it out, where to put the title text.

For example, this one in html works fine

<input type="text" name="tooltipform" title="Tooltip text">

In application.js it is determined by

$(window).load(function() {
$('#form-example [title]').tipsy({trigger: 'focus', gravity: 'w'});

});

I know that is something basic and I'm ashamed of my self. Thank you in advance.


回答1:


It's quite simple, pass it as an option:

<%= f.text_field :what, :title => "Tooltip text %>

Other html attributes can also be set as this, such as :class, :id, etc.




回答2:


Try with:

<%= f.text_field :what, :title => 'whatever' %>


来源:https://stackoverflow.com/questions/4984028/how-to-set-title-for-text-field

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