I'm trying
<%= f.input :provvigioni, :as => :number, :input_html => {:value => number_with_precision(f.object.provvigioni, precision: 2)} %>
Why edit have scrollbar????? I use formstatic & formtastic bootstrap
Thank's in advanced. Aesis.
Use
:as => :string
It will still accept decimal values
Related
I have a non-user model and it has attrs/db-columns, as "password" and there is one more "other password", for both when edited that object, their value do not appear inside textboxes
I did not find any suspicious code inside activeadmin-0.5.1 which would cause this.
Any hints?
Even if I use defaults or put the following, I get the same result
form do |f|
f.inputs "Details" do
f.input :user, :as => :select
f.input :type, :input_html => { :disabled => 'disabled' }
f.input :password
f.input :extra
f.input :other_password
end
f.actions
end
Seems like some filter on any field being edited having 'password' in its name ?
This is most likely due to formtastic's inferred field types, turning any field matching 'password' to be of type :password. Try setting those inputs using the :as => :string option:
form do |f|
f.inputs "Details" do
f.input :user, :as => :select
f.input :type, :input_html => { :disabled => 'disabled' }
f.input :password, :as => :string
f.input :extra
f.input :other_password, :as => :string
end
f.actions
end
I'm definitely a bit of a noob, so this might be something simple that I'm overlooking, however, the searches that I've done to try and find a solution have come up empty.
I've built a form using formtastic that has 5 input fields: two are text boxes and three are select lists.
<%= semantic_form_for #player do |f| %>
<%= f.inputs do %>
<%= f.input :firstname, :label => "First Name " %>
<%= f.input :lastname, :label => "Last Name " %>
<%= f.input :leagueid, :as => :select, :collection => League.all(:order => :leaguename), :label => "League " %>
<%= f.input :team_1, :as => :select, :collection => Team.all(:order => :name), :label => "Team 1 " %>
<%= f.input :team_2, :as => :select, :collection => Team.all(:order => :name), :label => "Team 1 " %>
<% end %>
<%= f.actions %>
<% end %>
What is happening is that the Teams lists work perfectly (the team names are displayed). However, the League list is a different story. All of the entries in the list look like this (with different a different code after 'League:'):
#<League:0x007fe29c406498>
If I use the form to create a Player, it works fine. The correct league ID goes into the database and everything. I just can't figure out why the names of the teams show, while whatever-that-is shows for the league.
Any and all help is appreciated.
When converting objects to String, Ruby will convert them to the memory address like you see unless you provide a to_s method for string conversions. I haven't used formtastic, but I believe adding a to_s method to your League class should cause it to display what you want.
Try adding
def to_s
#name # use whatever you want to be displayed.
end
to the League class.
You could try explicitly specifying the fields that should be used as the text and id within the select list. I believe it would look like.
<%= f.input :leagueid, :as => :select, :collection => Hash[League.all.map { |league| [league.leaguename, league.id] }]
The syntax is crazy. The call to map is returning an array of name/id pairs, like [ ['league1', 1], ['league2', 2] ]. Calling Hash on that converts it to a hash, like {'league1' => 1, 'league2' => 2}. Seems like the select list should use this hash to populate itself.
There's an example of this at http://rdoc.info/github/justinfrench/formtastic, under the Usage section.
:member_name is the solution I think.
<%= f.input :leagueid, :as => :select, :collection => League.all(:order => :leaguename), :label => "League " %>
Will probably work for you as
<%= f.input :leagueid, :as => :select, :member_name => :league, :collection => League.all(:order => :leaguename), :label => "League " %>
My problem was I have a model with a field the same name as the model and I think that confused Formtastic
Example scaffold:
rails g scaffold Countries code:string country:string
rails g scaffold Types title:string description:string
Model:
class Sign < ActiveRecord::Base
attr_accessible :title, :country_id, :type_id
belongs_to :country
belongs_to :type
Form View:
<%= f.input :type %>
<%= f.input :country, :member_label => :country %>
Having a form without the member_label leads to the object id displaying in the select box for countries although the ID is correctly saved. The type select worked perfectly without declaring member_label.
Note that I didn't need to specify :as => :select as formtastic can deduce this from the belongs_to relationship.
Try using :
<%= form.input :league, :member_label => :leaguename %>
This will override the naming convention of the Formtastic Column Select.
Have a look also at : Overriding the Column Name Convention wiki
Hope this helped.
I'm using simple_form and when the input is a date, I do:
<%= f.input :start_date, :label => t('start_date'), :as => :date, :start_year => Date.today.year - 90,
:end_year => Date.today.year, :discard_day => true,
:order => [:month, :year] %>
However, the month names are not correct to my locale. How do I change the localization file in order to get the correct names?
You DID get your standard rails locale from https://github.com/svenfuchs/rails-i18n/tree/master/rails/locale ?
I have a formtastic form to gather parameters for report generation. I know formtastic is designed to be used with models but I need to use it here as the form is in an activeadmin page.
It's all working well but I can't set a default value for the selects. I'm willing to implement a "despicable hack" to get this working. I'd prefer not to implement a fake model
just to set default values on a form.
The form code looks like this
<%= semantic_form_for "report", :url => report_admin_payments_path do |f| %>
<%= f.inputs do %>
<%= f.input :report_type, :as => :select, :collection => report_types, :input_html => {:style => "width:180px"} %>
<%= f.input :start_date, :as => :string, :input_html => {:class => 'datepicker', :style => "width:60px", :value => 1.month.ago.strftime("%Y-%m-%d")} %>
<%= f.input :end_date, :as => :string, :input_html => {:class => 'datepicker', :style => "width:60px", :value => Time.zone.now.strftime("%Y-%m-%d")} %>
<%= f.input :country, :as => :select, :collection => locales, :input_html => {:style => "width:180px"}%>
<% end %>
<%= f.actions :submit %>
<% end %>
Thanks in advance,
Matt
This or something similar should meet your needs.
class LightModel
# Subclass this for a model that looks like an ar model but has no persistence
# good for formtastic forms
include ActiveModel::Naming
include ActiveModel::Validations
def initialize(attributes = {})
#attributes = attributes
end
# read only atm
def method_missing(m, *args, &block)
#attributes[m]
end
end
Thanks,
Matt
When using formtastic in my rails3 application, I can't get the dropdown menus to work. Instead they appear as a selection list.
My code looks like this:
<%= f.label :slas, "Service" %></td><td><%= f.input :slas, :collection => #slas %>
Is this something I need to change in the css?
Wow, that took some fiddling.
In order to get a single dropdown list, instead of the select box, I needed to do this:
<%= f.label :slas, "Service" %></td><td><%= f.input :slas, :as => :select, :multiple => false, :input_html => { :size => 1 } %>
That was surprisingly hard...
That's strange. :as => :select should have done the trick by itself.