Code Monkey home page Code Monkey logo

simple_form's Issues

Need a better or easier to understand way to wrap collection labels

I tried using :label_text like so:

  =f.association :solution_types, :as => :check_boxes, :label_text=>lambda { |l| "#{l}<br/>"}, :collection => @solution_types

but it wasn't working. I don't really have time to debug, so I just put this hack in my js:

$("label.collection_check_boxes").each(function() { $(this).append("
")})

Problem with float type

By default simple_form for field ":as => 'float'", generate html source like this:

Input with type "number" (html5) by default have got attribute "step=1" in Chrome and Safari, so we can use only integer. And here is a problem integer instead float.

generator fails w/rails3?

in gemfile: gem 'simple_form', :git => "http://github.com/plataformatec/simple_form.git", :branch => "v1.0" (which would be handy in the readme if I have it correct)

rails generate simple_form:install git:master*
/Users/inspire/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/simple_form-179de2f/lib/simple_form/action_view_extensions/instance_tag.rb:36:in remove_method': methodto_check_box_tag' not defined in ActionView::Helpers::InstanceTag (NameError)
from /Users/inspire/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/simple_form-179de2f/lib/simple_form/action_view_extensions/instance_tag.rb:36:in send' from /Users/inspire/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/simple_form-179de2f/lib/simple_form/action_view_extensions/instance_tag.rb:36 from /Users/inspire/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/simple_form-179de2f/lib/simple_form.rb:3:inrequire'
from /Users/inspire/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/simple_form-179de2f/lib/simple_form.rb:3
from /Users/inspire/.rvm/gems/ree-1.8.7-2010.02/gems/bundler-1.0.0.rc.2/lib/bundler/runtime.rb:64:in require' from /Users/inspire/.rvm/gems/ree-1.8.7-2010.02/gems/bundler-1.0.0.rc.2/lib/bundler/runtime.rb:64:inrequire'
from /Users/inspire/.rvm/gems/ree-1.8.7-2010.02/gems/bundler-1.0.0.rc.2/lib/bundler/runtime.rb:62:in each' from /Users/inspire/.rvm/gems/ree-1.8.7-2010.02/gems/bundler-1.0.0.rc.2/lib/bundler/runtime.rb:62:inrequire'
from /Users/inspire/.rvm/gems/ree-1.8.7-2010.02/gems/bundler-1.0.0.rc.2/lib/bundler/runtime.rb:51:in each' from /Users/inspire/.rvm/gems/ree-1.8.7-2010.02/gems/bundler-1.0.0.rc.2/lib/bundler/runtime.rb:51:inrequire'
from /Users/inspire/.rvm/gems/ree-1.8.7-2010.02/gems/bundler-1.0.0.rc.2/lib/bundler.rb:114:in require' from /Users/inspire/Dropbox/newap/config/application.rb:4 from /Users/inspire/.rvm/gems/ree-1.8.7-2010.02/gems/railties-3.0.0.rc/lib/rails/commands.rb:15:inrequire'
from /Users/inspire/.rvm/gems/ree-1.8.7-2010.02/gems/railties-3.0.0.rc/lib/rails/commands.rb:15
from script/rails:6:in `require'
from script/rails:6

Styles

I have a feeling simple_form created forms would come with some styling. If so, what would I have to do to see/get it? This seems not to be documented, but I may be wrong.

Read only field ( merge show_for and simple_form )

Having a look at show_for and simple_form_for it seems to me that this 2 projects are some how very similar except that one is user to have editable content and the other on read only content.

    <% simple_form_for @user do |f| -%>
       <%= f.input :username %>
       <%= f.input :password %>
       <%= f.input :created_at %>
       <%= f.association :catagory %>
       <%= f.button :submit %>
    <% end -%>

    <% show_for @user do |u| %>
        <%= u.attribute :username %>
        <%= u.attribute :password, :in => :profile %>
        <%= u.attribute :created_at %>
        <%= u.association :catagory %>
    <% end %>

But it is often the case than in my applications i want to display a mix of read only data and editable for example if i want the created_at not to be editable, i would like to be able to do something like :

    <% simple_form_for @user do |f| -%>
       <%= f.input :username %>
       <%= f.input :password %>
       <%= f.input :created_at , :editable=> false %> # will generate an nice date output ( like u.attribute ) and not an ugly disabled html input or select
       <%= f.association :catagory %>
       <%= f.button :submit %>
    <% end -%>

And If you fellow this idea a bit futher, you realize that you could express the show_for by doing this:
<% simple_form_for(@user , :editable=> false )do |f| -%>
<%= f.input :username %>
<%= f.input :password %>
<%= f.input :created_at %>
<%= f.association :catagory %>
<%= f.button :submit %>
<% end -%>
In this case it will the show_for "render engine" and basically not create the

and the

Collection label_method and value_method

Hi Guys,

We use Simple Form in our projects for all our forms. We had a use case where we have an array of values available for selection but wanted the label to be translated, which label_method would not allow.

I created a fork (http://github.com/joshk/simple_form) which allows label_method and value_method to accept a lambda which can then do custom processing/transformation of the collection value.

I think this would be a good addition to Simple Form, but please let me know what you think.

Thanks a bundle,

Josh

What would be the _form.html.erb in haml?

Well, I tried this simple_form with haml but couldn't figure out what would be the equivalent of this form partial?
I create lib/templates/haml/scaffold/_form.html.haml via html2haml command.
But I don't think that the parsed file is haml equivalent. Here it is:
<%= simple_form_for(@<%= singular_name %>) do |f| %>
<% if @<%= singular_name %>.errors.any? %>
#error_explanation
%h2
<%= pluralize(@<%= singular_name %>.errors.count, "error") %> prohibited this #{singular_name} from being saved:
%ul
<% @<%= singular_name %>.errors.full_messages.each do |msg| %>
%li <%= msg %>
<% end %>
<% end %>
.inputs
- attributes.each do |attribute|
<%= f.<%= attribute.reference? ? :association : :input %> :#{attribute.name} %>
.actions
<%= f.button :submit %>
<% end %>

And this is my application.rb file
config.generators do |g|
g.stylesheets false
g.test_framework :rspec, :fixture => true, :view_specs => false,
:controller_specs => false, :helper_specs => false
g.fixture_replacement :factory_girl, :dir => "spec/support/factories"
g.template_engine :haml

FormBuilder test failing with NoMethodError

I just cloned the project and am getting a NoMethodError from one of the tests.

test_builder_should_generate_file_for_file_columns(FormBuilderTest):
NoMethodError: undefined method named_routes' for #<MockController:0x102534230> /Users/johnduff/.rvm/gems/ruby-1.8.7-p249@rails3/gems/actionpack-3.0.0.beta3/lib/action_view/test_case.rb:151:inmethod_missing'
./test/form_builder_test.rb:136:in test_builder_should_generate_file_for_file_columns' /Users/johnduff/.rvm/gems/ruby-1.8.7-p249@rails3/gems/activesupport-3.0.0.beta3/lib/active_support/testing/setup_and_teardown.rb:64:insend'
/Users/johnduff/.rvm/gems/ruby-1.8.7-p249@rails3/gems/activesupport-3.0.0.beta3/lib/active_support/testing/setup_and_teardown.rb:64:in run' /Users/johnduff/.rvm/gems/ruby-1.8.7-p249@rails3/gems/activesupport-3.0.0.beta3/lib/active_support/callbacks.rb:433:in_run_setup_callbacks'
/Users/johnduff/.rvm/gems/ruby-1.8.7-p249@rails3/gems/activesupport-3.0.0.beta3/lib/active_support/testing/setup_and_teardown.rb:62:in `run'

Errors delimiter and i18n / configuration.

Hi again,

I was attempting to find out how I could change the language of the delimiter of the error messages.

Currently when you for example have a "validates_presence_of :name" in a model and this field in the form has not been filled in, by default you get something like this:

can't be blank

Now if you add another validation, just for the sake of this example: "validates_length_of :name :between => 3..20" then you get the following error message:

can't be blank and is too short (minimum is 3 characters)

So regarding the and delimiter. Is there currently a way to specify in the configuration file or yaml locale file to change this to for example the Dutch en delimiter? Also is there a way to for example list (ul/li) rather than sentence them?

Thanks

Labels for radio buttons are not linked correctly

Consider the following example

= f.input :salutation, :as => :radio, :collection => ['Mr','Ms']

Here is what one of those radio_button/labels looks like

Mr

Notice how the label's for attirbute does not coincide with the input's dom id (user_salutation_mr vs user_salutation_Mr). Perhaps a simple downcase would do the trick?

work with datamapper

There's no mention of activerecord in the source that I can see, but it calls .mappings, which I don't think DM supports? Know if anyone's worked on DM compatibility?

    klass = self.class.mappings[input_type] ||
      self.class.const_get(:"#{input_type.to_s.camelize}Input")

Thanks,
Kevin

Association helper does not use correct primary key if it is other than "id"

It seems that association method does not use non-standard primary key even if it is defined in the model.

This works:
<%= f.association :game, :collection => Game.multiplayer.order('name'), :value_method => Game.primary_key %>

This doesn't:
<%= f.association :game, :collection => Game.multiplayer.order('name') %>

Is this intended behavior or a bug?

config.error_method

From the new release I noticed a lot of great new features, however I was also wondering why my error messages started changing. I see the change is related to config.error_method now has options, but the possible values aren't listed anywhere. I had to dig through all the commits to see that the option I wanted was :to_sentence instead of :first.
Could you update the docs/release notes/default initializer to let people know this? Thanks!
(It's possible that maybe this option is common knowledge. Sorry if so; I am new to rails!)

Gemfile not valid error while installing with bundler via git

i get the following error:

simple_form at /home/jo/.bundle/ruby/1.8/bundler/gems/simple_form-917206bb6c5458ef73c7b90fe49bfa5e4cbdde9d-master did not have a valid gemspec.
This prevents bundler from installing bins or native extensions, but that may not affect its functionality.
The validation message from Rubygems was:
  ["test/support/country_select/init.rb", "test/support/country_select/install.rb", "test/support/country_select/lib/country_select.rb", "test/support/country_select/uninstall.rb"] are not files

However, when I run
rake gemspec:validate
it tell me:
simple_form.gemspec is valid.

Greetings
Johannes

collection can't handle symbols

When specifying a collection to select, if the collection is an array of symbols, the form will generate ids for the symbol instead of using the string:

<%= f.input :gender, :as => :select, :collection => [:male, :female], :include_blank => false %>

<select name="user[gender]" id="user_gender" class="select optional">
    <option value="1637780">male</option>
    <option value="1637876">female</option>
</select>

Association not found

In models I have:

doctor.rb

has_many :assignments
has_many :specialties, :through => :assignments

specialty.rb

has_many :assignments
has_many :doctors, :through => :assignments

In doctors/_form.html.erb

<% simple_form_for([:admin, @doctor]) do |f| %>
  <div class="inputs">
    ...
    <%= f.association :specialty %>
  </div>
  ...
<% end %>

Following error is occured:

Association :specialty not found

BTW does simple_form supports has_many_through associations?

Using edge from Gemfile doesn't work anymore

In my Gemfile I had something like this which was was working fine until recently:
gem "simple_form", :git => "git://github.com/plataformatec/simple_form.git"

I had cleared out my gems and rebundled and now I get undefined methodsimple_form_for'`

If I change my gemfile to just be gem "simple_form" it works fine, but it would be nice to reference the edge.

I'm using Ruby 1.9.1 and Rails3-beta3

Rails 3 RC: SimpleForm::FormBuilder#association calling undefined method 'returning'

Rails 3 RC has without warning or fallback support dropped support for Object#returning. It's been replaced by Object#tap. No deprecation notices, just a quick comment in the CHANGELOG (one of many Beta to RC changes that has been sudden without any form of migration; e.g. config.autoload_paths....)

As a result, any f.association calls throw ActionView::Template::Error

More HTML5 goodness, please!

Seeing as Chrome 6 now joins Safari in adding custom UI on top of <input type="number"/> elements, it would be awesome if it was easier to add the new attributes to the element.

In particular, min, max, and step would improve the experience, also on mobile devices.

Could these be inferred by the presence of a NumericalityValidator? Otherwise, allowing these options directly in the input call would be preferred over having to use :input_html.

I love simple_form!

Custom getters for inputs

Hi!

In my form I have some inputs that should get their values populated from a specific method rather than from the attribute. One of these inputs is called, let's say, 'price', and while in the database the value is 1234 (self[:price]) I have set up a custom getter which divides it by 100 (using acts_as_decimal gem) so that self.price == 12.34.
Unfortunately, simple_form gets the "raw" attribute (1234), so that when you edit the form you get 1234. Any ideas to force simple_form to get the model method rather than the attribute? Thanks!!

Wrapping collection check boxes

Is there a way of wrapping every check box or a radio button in some html tag?
For example:
Set the initializer config:
SimpleForm.setup do |config|
...
config.collection_check_boxes_wrapper_tag = :li
...
end

and in the view file:


    <%= f.collection_check_boxes :category_ids, Category.all, :id, :name %>

so every check box gets wrapped in <li> tag which can be easily arranged at designer's will.

Or passing the wrapper tag directly in the view as a hash
<%= f.collection_check_boxes :category_ids, Category.all, :id, :name, :wrapper => :li %>

p.s. I think there is an error in docs Collection Check Box section
f.collection_check_box :options, [[true, 'Yes'] ,[false, 'No']], :first, :last
should be
f.collection_check_boxes :options, [[true, 'Yes'] ,[false, 'No']], :first, :last

undefined method `country_select' for #<SimpleForm::FormBuilder:0x1039dd9c0>

Hi, I'm using an clean setup of Rails 3 with SimpleForm, in tests and development I'm getting this error for a field labeled "country". It needs an extra manual setup to work? Also I mean this bug can be happening because I'm using Mongoid, the country select has any dependency on ActiveRecord directly? Or in end its a bug on version 1.2.2?

Swap rendering order for checkbox and label

Hi,

I couldn't find the solution so I will just ask it here.
I have a couple simple forms and I prefer for checkboxes and radiobuttons to swap the rendering order for these with the label. So instead of having:

[label] [checkbox]

I would like to have:

[checkbox] [label]

That way if you render like 10 checkboxes it looks a lot less messy in the web browser.
Is there any way to accomplish this?

Thanks!

UPDATE

I basically have something like this, since im using Devise:

<%= simple_form_for @user do |f| %>
  <%= f.input :username, :label => 'Your username please' %>
  <%= f.input :password, :hint => 'No special characters.' %>
  <%= f.input :remember_me, :as => :boolean %>
  <%= f.button :submit %>
<% end -%>

This is about the :remember_me, :as => :boolean part. I would like to just swap the label and checkbox rendering order if possible.

questions

The form includes accept-charset="UTF-8" by default - where is this in the source so I can add an option to skip it? My site isn't currently UTF-8 due to some old content.

How do I wrap non-semantic fields in the row+label wrappings? I'd thought it would be like f.text_field, but that appears to be the same as f.input. Sometimes you'll need to submit things that aren't values on an object, and for design's sake it'd be nice to have it formatted like the rest of the content.

Also, any reason you didn't add method_missing support, to allow things like f.name instead of f.input :name?

Readme forgets about Bundle config

In order to run the simple_form_install generator you have to instruct Rails through Bundle:

in Gemfile:

gem 'simple_form' 

and then you're redy to go with the generator.

association does not work

I have installed your gem with rails 3 and I've bee creating an app, I used the simple_form_install command so now all my scaffolds are generated with simple_form, but when I use association it gives me this error.
undefined method `merge_conditions' for #Class:0xb63db7e0

class Country < ActiveRecord::Base
  has_many :organisations

  validates_presence_of :name, :abreviation

  def to_s
    name
  end
end


class Organisation < ActiveRecord::Base
  belongs_to :country
end

And the form for organisation

<% simple_form_for(@organisation) do |f| %>
  <div class="inputs">
    <%= f.association :country %>
    <%= f.input :name %>
    <%= f.input :address %>
    <%= f.input :address_alt %>
    <%= f.input :phone %>
    <%= f.input :phone_alt %>
    <%= f.input :mobile %>
    <%= f.input :email %>
    <%= f.input :website %>
  </div>

  <div class="actions">
    <%= f.button :submit %>
  </div>
<% end %>

Compatibility with non-error forms

Using Rails 3.0, SimpleForm 1.2.2 and MetaSearch 0.5.3, I'm trying to create a search form.

So I've got in my controller:
@search = Post.search

And in my view, since I prefer SimpleForm's builder over the default one, I'd like to write:
= simple_form_for @search do |form|
= form.input :title_contains
= form.button :submit

Unfortunately, this doesn't work, because SimpleForm expects @search to respond to the "errors" method, which it doesn't.

My suggestion would be to return that there are no errors in the field if the object doesn't respond to that method, so simple_form would be compatible with forms such as search forms.

BTW: great work in bringing Formtastic power to Rails 3 and making it more simple!

Thanks.

Rails update to version 2.3.8, error :undefined method `html_safe!'

Hi,

I've just updated my Rails gem version from 2.3.5 to 2.3.8
I'm using simple_form v=1.0

When I try to render a form I have an error message :
undefined method `html_safe!' for #String:0x1045237d0

Can I patch it in my app or maybe it must be fixed in the simple_form version 1.0 ?

Thx

Fieldset support?

Is it just me, or is simple_form currently missing fieldset support?
One of my favourite features of Formtastic is the ability to write:

semantic_form_for @entry do |f|
  f.inputs "A fieldset" do
    f.input :title
    f.input :body
  end
  f.button :submit
end

But I can't see this anywhere in the documentation or class. Consider this a feature request if it doesn't already exist. ;)

CSS+simple format

I just give a try to simple_format...
I wonder why the text fields are size 255 by general. I only can slim them down with input[:text]. But then it is impossible to have smaller sizes, for zip code f. expl.
For more complex and longer forms I need much more flexibility.

Greetings

request, field with errors ?

More a request,

Just starting to use your gem.

I would like to add the class field_with_errors to the input field which has the errors,
in order to style it with CSS and to hook up javascript code. Is this possible ?

At the moment the input field and its label are wrapped in a div with class field_with_errors

Thanks

multipart

Is there a way to use simple_form with enctype multipart?

label_method => lambda

hello,

<%= f.input :type,
            :collection => @entity_types, 
            :label_method => lambda {|x| x[0]},
            :value_method => lambda {|x| x[1]} %>

produces:

TypeError in Entity_images#index

Showing /.../index.erb where line #18 raised:

<Proc:0x000001036c5580@/.../index.erb:18 (lambda)> is not a symbol

with @entity_types = [['Produto', 'product'], ['Kit', 'kit'],['Categoria', 'category']]

any idea what is wrong here?

Installation via rubygems fails

Hi folks!

I would like to thank you for a fantastic piece of code I ever wanted and never know but the first hurdle on my trial is the installation via rubygems:

Another, old and depricated in favor of MailForm gem gets installed instead of this (maybe but I guess) form- aeh - fantastic lib.

Greetings
Johannes

Overwriting Default HTML options

I need to know how to overwrite/change the default generated markup. I like how simple_form works, but I want to customize it in order to make it render nicely with the web-app-theme's html.

Is there a way? Any good practice?

Thanks!
Lucas

Validation reflection

Would be great to have simple_form use the model validations to determine whether a field is required. Right now formtastic does this in tandem with validation reflection plugin, but it may be a better idea to reflect on ActiveModel's validations in Rails 3.

PS - obviously this is a feature request - is this a good place to post them?

Different class for error divs on labels

More of a feature request, a small one at that

One thing I miss from formtastic is the distinction:

<div class='labelWithErrors'><label>...
<div class='fieldWithErrors'><input>...

Order of boolean elements

If an input is boolean, then semantically the checkbox should come before the label, not after it

โˆš Label

not

Label โˆš

How does one change the (pseudo) verb of a form?

If I do

<%= simple_form_for NewsletterRegistration.new, :html => { :method => :delete } do |f| %>
<%= f.input :email %>
<%= f.submit "ok" %>
<% end %>

my form points to the index/get. How could I have it use the delete verb?

Textarea properties

Hi

Is it possible to set the rows/cols properties for a textarea input. I have tried the following:
= form.input :notes, :label => 'Notes', :rows => 10

Maybe I am missing something.

Thanks

Forms without HTML 5

Simple From creates HTML 5 automatically based on the column name (e.g. email). What if I don't want to use HTML 5 not yet. Using Simple Form with HTML causes different behavior on browsers, e.g. Chrome vs FF.

Is there a way to disable the HTML 5 output? If not I think it's necessary to make the output optional.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.