Formtastic, native: as input type

How can I add my own field types in formtastic?

For example, I need to have user datetime data input, and I want something like this:

<%= f.input :start_date , :as => :my_date %>

This obviously does not work, because formtastic does not know: my_date (only: boolean ,: string ,: datetime, etc.)

But how can I add additional input types?

+5
source share
2 answers

You need to add a custom input method:

class MyCustomFormtasticFormBuilder < Formtastic::SemanticFormBuilder
  protected
  def my_date_input(method, options)
    basic_input_helper(:text_field, :my_date, method, options)
  end
end

This is ideal for, say, the new HTML5 input types. You use it like this:

<% form_form @model, :builder => MyCustomFormtasticFormBuilder  do |f| %>
   <%= f.input :start_date, :as => :my_date
<% end %>
+9
source

Dont subclass Formtastic :: FormBuilder more

Formtastic 1.x Formtastic:: FormBuilder . Formtastic 2 .

https://github.com/justinfrench/formtastic

http://justinfrench.com/notebook/formtastic-2-preview-custom-inputs

+4

All Articles