简体   繁体   English

如何将ng-keyup添加到rails text_field helper for form_for

[英]how to add ng-keyup to rails text_field helper for form_for

I'm having a problem figuring out how to add an ng-keyup to a rails text_field helper used with form_for. 我在弄清楚如何将ng-keyup添加到与form_for一起使用的rails text_field帮助器时遇到了问题。 This <%#= f.text_field :email, ngkeyup: "checkEmail()" %> comes close but adding the dash in ngkeyup causes it to error out and trying to make it a string doesn't work. 这个<%#= f.text_field :email, ngkeyup: "checkEmail()" %>接近但在ngkeyup中添加短划线会导致错误输出并尝试使其成为字符串不起作用。

I have (but this is obviously not working): 我有(但这显然不起作用):

<%= form_for @user do |f| %>
  <%#= f.text_field :email %>
  <%#= f.text_field :email, options: {ng-keyup:"checkEmail()"} %>
  <%#= f.text_field :email, {ng-keyup:"checkEmail()"} %>
  <%#= f.text_field :email, ng-keyup:"checkEmail()" %>
  <%= f.text_field :email,,ng-keyup:"checkEmail()" %>
  <div id='email-status'></div>
<% end %>

and would like 并希望

<input id="user_email" name="user[email]" size="30" type="text" ng-keyup="checkEmail()">

I really just need to get the ng-keyup value in here. 我真的需要在这里获取ng-keyup值。

thx for any help thx任何帮助

Running rails 4.0.1 this did the trick for me: 运行rails 4.0.1这对我有用:

<%= f.text_field :email, "ng-keyup" => "checkEmail()" %>

There are many other cases in which Rails won't accept any other key-value syntax expect the one with the hashrocket. 在许多其他情况下,Rails不会接受任何其他键值语法期望具有hashrocket的语法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM