2012-12-08 70 views
2

我正在使用simple_form和Rails 3.2.5。我有一個看起來像這樣的形式:如何將Javascript添加到simple_form?

<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => {:class => 'form-vertical' }, :html => {:name => "new_user"}) do |f| %> 
    <%= f.error_notification %> 
    <%= f.input :field_one, 
       :placeholder => '30000', 
      :autofocus => true, 
      :required => true, 
      :html => {:onFocus => 'startCalc();'}, 
      :html => {:onBlur => 'stopCalc();'} %> 
# More form fields 

<% end %> 

我想要當用戶輸入表單字段輸入一個數字,但JavaScript是不顯示在輸出HMTL高達調用JavaScript驅動的計算:

<input autofocus="autofocus" class="numeric decimal required" id="field_one" name="user[field_one]" placeholder="30000" step="any" type="number" /> 

有誰知道怎麼去simple_form添加這些JavaScript位?

謝謝!

Greg

回答

3

我現在看到我的錯誤。由於每simple_form documentation,我需要使用:

:input_html => {:onFocus => 'startCalc();'}, 
:input_html => {:onBlur => 'stopCalc();'} 

這工作!