2

I'm using simple_form with Rails 3.2.5. I have a form that looks like this:

<%= 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 %>

I'm trying to call a Javascript driven calculation when a user enters a number in the form field, but the Javascript isn't showing up in the outputted HMTL:

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

Does anyone know how to get simple_form to add these bits of Javascript?

Thanks!

Greg

1 Answer 1

4

I see my error now. As per the simple_form documentation, I need to use:

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

This works!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.