justinfrench / formtastic
- Source
- Commits
- Network (117)
- Issues (26)
- Wiki (5)
- Graphs
-
Branch:
master
-
Be able to specify save and create labels for commit_buttons
3 comments Created 5 days ago by pupenoCurrently, commit_buttons automatically show different labels for creating a new record or saving a record. That is great! It would be nice if you could override the labels maintaining that functionality (not just giving one string) so instead of:
<% if @item.new_record? %> <%= form.commit_button "Add Candidate" %> <% else %> <%= form.commit_button "Save Candidate" %> <% end %>one could write
<%= form.commit_button :new => "Add Candidate", :existing => "Save Candidate" %>or something like that.
Comments
-
In v0.9.7 it seems to be an issue to get Formtastic to set date value as nil
Comments
justinfrench
Tue Dec 29 14:53:43 -0800 2009
| link
Closing, duplicate.
-
Paperclip attachment destroyed on update with Formtastic
2 comments Created 8 days ago by ThrolkimWhen updating a model with a Paperclip attachment with a Formtastic form, if no new image is uploaded and the file field is left blank - the attachment is deleted and the previous value is not carried over. I'm assuming this is a bug, as it's rather a pain in the arse!
Comments
Ignore this, I'd cocked up and was using the wrong method for the form. Took me waaaaay too long to spot that.
Many apologies, Merry Christmas, and thanks for an awesome gem :)
-
belongs_to input fields doesn't show error messages in the foreign key
2 comments Created 10 days ago by dfmonacoHere is an example:
The model:Class Project < ActiveRecord::Base belongs_to :company validates_presence_of :company_id endThe View: (in haml)
- semantic_form_for @project do |form| - form.inputs do = form.input :company - form.buttons do = form.commit_buttonThe generated form won't display the error message if a company is not selected, this is because in the Formtastic::SemanticFormBuilder#input method the existence of an error is checked against the Project#company method an not in Project#company_id where the error really is.
To fix this I had to replace the line:
= form.input :companywith:
= form.input :company_id, :as => :select, :collection => Company.alland now it works as expected, but the simplicity is gone.
I think the problem is in the following line of code in Formtastic::SemanticFormBuilder#input:
html_class << 'error' if @object && @object.respond_to?(:errors) && !@object.errors[method.to_sym].blank?where the argument method is in this case :company, and not :company_id.
Thank you for the great job you are doing with this library ( I am a beginner , so excuse me please if I am wrong, I am just trying to help)
Comments
-
Unable to create a date select with nothing selected
2 comments Created 13 days ago by twalpoleThe or'ing with default_time in date_or_datetime_input prevents the setting of :selected to nil or of the object method returning nil from having the desired effect of nothing selected in the date dropdowns.
Comments
Could you please provide a failing spec or a full code example with expectations?
Oh, duplication of issue: http://github.com/justinfrench/formtastic/issues/#issue/152. Closing this one.
-
label_str_method overrides activerecord i18n if not set to default.
3 comments Created 25 days ago by lardawgeAs pointed out by aaronchi here: http://github.com/justinfrench/formtastic/commit/280897a7cf939c7056a3eccb5ebb522a70efad0f#comments
The last commit breaks i18n for everyone who wants to only use activerecord translation for only a few fields as well as label_str_method. It basically would use label_str_method globally.Originally I didn't see this as a problem since you could always use formtastics i18n in place of it. However, for people who have large apps and want to switch to formtastic, this would be useful (and I admit after using it I like the flexibility as well). So here is a a patch to hopefully cover everyone.
http://github.com/lardawge/formtastic/commit/15ae428c4659cd831b8b47493af8642d492e5cc9
Comments
-
Per this thread on google:
http://groups.google.com/group/formtastic/browse_thread/thread/648031a11ef3e335Fix is here:
http://github.com/lardawge/formtastic/commit/3b60fc4ab6bbda3d2c51ecf57e179dc6de4cecd2Was applied, then reverted, making a new issue since github's doesn't offer me the choice of re-opening, so here's a new issue some we can try again.
See 141 and 147
Comments
Ok, Sorry about all the issues with the previous patch :)
Here is a patch that should cover all use cases and keep the current tests intact while adding a new one for this issue.
http://github.com/lardawge/formtastic/commit/984d7b0d08070710f5fdb101d3325451bb72d2f7
I can't think of a use case where you would need to use translation via activerecord but still use label_str_method for non-activerecord objects. I assume if you rely on translation it would be for everything. So setting label_str_method overrides activerecord if changed from default.
justinfrench
Thu Dec 03 14:28:50 -0800 2009
| link
Don't think so, looks like there is still a failure even with my change removed... Something changed however.
My bad, applied the patch without running specs, already fixed! :) Used with_config since the spec was changing config values.
I stand corrected :)
Note to self, run FULL spec suite before AND after any changes.
justinfrench
Thu Dec 03 15:06:30 -0800 2009
| link
Yeah, that's why I added the with_config block... it was too easy to change a config value and break any specs that followed it.
-
I have my translations in scope: "activerecord.attributes.model.attribute"
Now formtastic doesn't take them at all.
It makes @@label_str_method on key (humanize by default).
Do I really need to rewrite all my translations to scope: "formtastic.labels.model.attribute"
I don't think is a good idea.Above changes were made by this commit:
http://github.com/justinfrench/formtastic/commit/863e3ffc6bdd19499379b7f1adfe67740b60df2bComments
I noticed this as well. I believe the class will respond to human_attribute_name even if the translation is not defined explicitly. In that case, it just returns a humanized version of the attribute. You may need to do something more clever like compare the human_attribute_value to a humanized string and use the label_str_method only if they match.
Justin, Now we know what broke... I will have a look...
justinfrench
Thu Dec 03 11:36:09 -0800 2009
| link
Ok, looks like José reverted your patch on master. I'm going to revert the doc patch that went with it. Clearly we need some specs that describe the current behaviour well, then we can figure out a patch that works for everyone.
I'm going to go make an un-broken gem ;)
justinfrench
Thu Dec 03 11:36:51 -0800 2009
| link
Changed tags to 1.x too, happy for it to be done sooner, but it's not a blocker.
justinfrench
Thu Dec 03 12:46:46 -0800 2009
| link
Ah, this should be closed as I've pushed a new gem, will find the previous issue and re-open.
-
6 comments Created 28 days ago by tfolk! next patchxbug (verified)xFormtastic 0.9.5 breaks select fields for belongs_to associationsfor 1.0xI have the following model
class Address < ActiveRecord::Base belongs_to :country #etc...And the following in the view
= form.input :country, :include_blank=>false, :label_method => :printable_nameIn Formtastic 0.9.3 I get the expected output:
<select name="address[state_id]" id="address_state_id"> #etc...But in 0.9.5, FT is appending a [] to the name attribute:
<select name="address[state_id][]" id="address_state_id"> #etc...This causes the controller to misassign the state attribute because it's getting an array which includes the selected value instead of the value itself.
Comments
+1 I get around this for the time being by using :input_html => { :name => '.....' } but it's not ideal. Perhaps a test for this ;-)
OK, I got it. For some reason there are missing specs for name attributes. I got this one failing as well, will just trace it down now.
Note: The Rails select helper don't treat :multiple => nil as "no value", the :multiple option key must not exist in such cases. xP
Fixed the mysterious incorrect DOM name generated for select + belongs_to. Closed by a9651db.
justinfrench
Thu Dec 03 02:27:07 -0800 2009
| link
Pulled, new gem pushed.
-
11 comments Created 29 days ago by sauberia! next patchxpartial generation doesn't use namespacefor 1.0xIf I prefix the model name with the controller namespace the generator creates the namespace directory as expected but then attempts to create the partial in a directory one up from that:
script/generate form admin/thing --partial --haml
create app/views/admin/things
create app/views/things/_form.html.haml
No such file or directory - /Users/marc/Sites/test/app/views/things/_form.html.hamlIf I add the controller_class_path variable in the following line from form_generater.rb:
m.template "view__form.html.#{template_type}", File.join(VIEWS_PATH, controller_class_path, controller_file_name, "_form.html.#{template_type}")It attempts to create the file in the correct directory but then I get the error
uninitialized constant Admin::ThingI guess it thinks admin is the model module and the controller namespace or summink.
I'm a wee bit out of m depth here so this may not be an issue.
Comments
I've ended up changing:
@class_name.constantize.content_columns.rejectto
@singular_name.classify.constantize.content_columns.rejectand it works for my purposes
OK, this is not really a bug - because this is somewhat odd scenario. You should specify the model name, I'm 90% sure this is the way Rails handles it as well. The form layout don't depend on any details in the controller, rather the model. Closing.
justinfrench
Wed Dec 02 01:48:48 -0800 2009
| link
Hang on, I agree that the arg is intended to only be the model name, but...
the code should be more resilient to such misconceptions -- perhaps throw an error if there's a slash or :: namespace in the model param?
it's still a valid suggestion that you can choose where in the view hierarchy this should go, perhaps with a second arg?
script/generate form thing admin/thing --partial
?
This doesn't seem to do the trick:
script/generate form admin/thing --partial --haml
create app/views/admin/things
create app/views/things/_form.html.haml
No such file or directory - /Users/marc/Sites/test/app/views/things/_form.html.haml
sg form admin::thing --partial --haml
exists app/views/admin/things
create app/views/things/_form.html.haml
No such file or directory - /Users/marc/Sites/test/app/views/things/_form.html.hamlOdd, I think I need to spend more time on this one...Rails generator internals is a mess (really) - good thing Rails 3 will rock a shiny new one.
This works for me, but I had to add a optional flag (--controller CONTROLLER_PATH) to support all three major cases:
http://github.com/grimen/formtastic/commit/827c6c786acdab8864c4dffcaf58958b72e307dc
Meaning: Model might be namespaced - or might not, and that could be a mess in Ruby 1.9.
Brilliant!
script/generate form thing --partial --controller admin/things
exists app/views/admin/things
create app/views/admin/things/_form.html.erb
Appreciated :)
Fix for the form generator: Allows controller namespace to be specified, but strips out the namespace for the model. Closed by 24ec121.
justinfrench
Wed Dec 02 11:53:08 -0800 2009
| link
pulled in, closing
-
When using formtastic with authlogic's UserSession class I am getting this error:
undefined method `content_columns' for UserSession:Class formtastic (0.9.4) rails/./lib/formtastic.rb:424:in `content_columns' formtastic (0.9.4) rails/./lib/formtastic.rb:1125:in `field_set_and_list_wrapping' formtastic (0.9.4) rails/./lib/formtastic.rb:272:in `inputs'Comments
Weird, the rescue don't trap that one... =S
self.model_name.constantize.content_columns.collect { |c| c.name.to_sym }.compact rescue []...haven't tried it myself yet, but as u running 0.9.4...
I can't reproduce this in a spec (did my own non-activerecord-dummie-class without any methods/attributes). Could you maybe?
kristopher
Tue Dec 01 10:25:14 -0800 2009
| link
It is erroring on line 424 which is not rescued. Try testing it again with a single attribute and pass an object to semantic_form_for
class Foo attr_accessor :attr endThis works:
<% semantic_form_for(:foo, :url => '/' do |f| %> <%= f.inputs :attr %> <% end %>This errors:
<% semantic_form_for(Foo.new, :url => '/' do |f| %> <%= f.inputs :attr %> <% end %>Which is expected since the symbol fails the conditional check on line formtastic.rb:423 and is rescued on line formtastic.rb:426. But when passed an object it passes the conditional check and gets the undefined method error since it is not rescued on line formtastic.rb:424.
Hope that helps.
Oh, peep the master version - this one is patched (actually more like refactored, but handles such errors with the line I dropped in the first reply) already for 0.9.5. Stay tuned.
kristopher
Tue Dec 01 11:06:53 -0800 2009
| link
Cool man, thanks for looking at it.
-
When I added :discard_month or :discard_day, builder also generate html hidden field for them:
<%= form.input :birth_year, :as => :date, :start_year => 1950, :discard_month => true, :discard_day => true, :input_html => {:name => "birth_year", :name => "birth_year",:class => "required"}%>The generated HTML code:
<input id="video_birth_year_2i" type="hidden" value="1" name="video[birth_year(2i)]"/> <input id="video_birth_year_3i" type="hidden" value="1" name="video[birth_year(3i)]"/>Then I can't add attr(birth_year(2i),birth_year(3i)) to model to make the submit successful..what should i do ?
The source code:
if options[:"discard_#{input}"] break if time_inputs.include?(input) hidden_value = datetime.respond_to?(input) ? datetime.send(input.to_sym) : datetime hidden_fields_capture << template.hidden_field_tag("#{@object_name}[#{field_name}]", (hidden_value || 1), :id => input_id)What is the purpose for the hidden field?
Comments
justinfrench
Tue Dec 01 03:08:19 -0800 2009
| link
The hidden values are there because Rails expects the three-part date params to all be there. :discard_month means it will render a hidden input for the month "1" instead of a select box of options. This is also exactly what Rails does with date_select.
I don't think :as => :date should be your chosen input here. It looks like you just want to pass in a year, in which case a :select with a :collection of relevant years will do. Either way, this isn't a bug, so I'm closing it. Please discuss on the google group if need be.
-
7 comments Created about 1 month ago by lardawge! next patchx@grimenxlabel_str_method = no change@joséxPer this thread on google:
http://groups.google.com/group/formtastic/browse_thread/thread/648031a11ef3e335Fix is here:
http://github.com/lardawge/formtastic/commit/3b60fc4ab6bbda3d2c51ecf57e179dc6de4cecd2Comments
justinfrench
Wed Dec 02 01:42:43 -0800 2009
| link
Awesome. It doesn't apply on master, but it should be easy for me to coerce! I can't shake the feeling that I'm missing something here.... I wonder why it was ever this complex? Grimen? José?
I got no clue, I haven't looked into that specific functionality at all - there are some contexts of the code that I'm not really know anything about. =)
justinfrench
Wed Dec 02 02:21:03 -0800 2009
| link
Fuck it, I'll apply it and see what happens ;)
justinfrench
Wed Dec 02 02:29:58 -0800 2009
| link
Applied, with a little coercion :)
http://github.com/justinfrench/formtastic/commit/863e3ffc6bdd19499379b7f1adfe67740b60df2bClosing.
justinfrench
Thu Dec 03 12:48:50 -0800 2009
| link
This patch was reverted. How do I re-open an issue? Github's busted?
justinfrench
Thu Dec 03 12:52:17 -0800 2009
| link
See 147
justinfrench
Thu Dec 03 12:53:43 -0800 2009
| link
See 148 I mean.
-
11 comments Created about 1 month ago by alec-c4! next patchx@justinxWrong render of :datefor 1.0xHi, could you tell me plz - why on code
- semantic_form_for :profile, :html => { :method => :put }, :url => update_profile_path do |form| - form.inputs do = form.error_messages = form.input :female, :as => :select, :collection => [["Male", false], ["Female", true]] = form.input :birthdate, :as => :date, :start_year => 1900 = form.input :timezone, :as=> :time_zone - form.buttons do = form.commit_button "Save"formtastic renders
<li class="date required" id="profile_birthdate_input"><fieldset><legend><span class="label">Birthdate<abbr title="required">*</abbr></span></legend><ol><li><label for="profile_birthdate_1i">Year</label><select id="profile_birthdate_1i" name="profile[birthdate(1i)]"> <option value="1900">1900</option> <option value="1901">1901</option> <option value="1902">1902</option> <option value="1903">1903</option> <option value="1904">1904</option> <option value="1905">1905</option> <option value="1906">1906</option> <option value="1907">1907</option>........................
<option value="2014">2014</option> </select> </li><li><label for="profile_birthdate_2i">Month</label><select id="profile_birthdate_2i" name="profile[birthdate(2i)]"> <option value="1">114</option> <option value="2">97</option> <option value="3">110</option> <option value="4">115</option> <option value="5">108</option> <option value="6">97</option> <option value="7">116</option> <option value="8">105</option> <option value="9">111</option> <option value="10">110</option> <option value="11">32</option> <option value="12">109</option> </select> </li><li><label for="profile_birthdate_3i">Day</label><select id="profile_birthdate_3i" name="profile[birthdate(3i)]"> <option value="1">1</option> <option value="2">2</option> .......................... <option value="30">30</option> <option value="31">31</option> </select>plz have a look at year field (why ended at 2014?) and month (very strange - digits instead month names) :(
Comments
Question 1: "Why ended at 2014?"
You can adjust this using Rails core options (e.g. :end_year):
http://railsapi.com/doc/rails-v2.3.4/classes/ActionView/Helpers/DateHelper.html#M005680
Question 2: Digits instead of month names...
Passing this ball to Justin, I never seen such behavior and don't really got a qualified guess why right now. =S
justinfrench
Tue Dec 01 03:10:37 -0800 2009
| link
Those months look really odd. Will look into it.
Questions: 1. Are you using Globalize? 2. Have you tried to remove other plugins to see if behaviour still exists? Similar problems seems to be an issue with Globalize.
justinfrench
Wed Dec 02 01:57:37 -0800 2009
| link
I just added a spec locally to ensure that this bug isn't in master, and the spec passed:
it 'should use month name' do output_buffer.should have_tag('form li.date fieldset ol li select option', /^jan/i) endI'm closing this for now because it sounds like an incompatability, please feel free to re-open, or nag us on the Formtastic google group.
Not using globalize but still having this issue!
I realize it happens on the built in I18n, but only when the locale is not :en.
-
Hi, could you tell me plz - why on code
- semantic_form_for :profile, :html => { :method => :put }, :url => update_profile_path do |form|e
- form.inputs doe
= form.error_messagese e
= form.input :female, :as => :select, :collection => [["Male", false], ["Female", true]]e
= form.input :birthdate, :as => :date, :start_year => 1900= form.input :timezone, :as=> :time_zone
e
- form.buttons doe
= form.commit_button "Save"formtastic renders
<li class="date required" id="profile_birthdate_input"><fieldset><legend><span class="label">Birthdate<abbr title="required">*</abbr></span></legend><ol><li><label for="profile_birthdate_1i">Year</label><select id="profile_birthdate_1i" name="profile[birthdate(1i)]"> <option value="1900">1900</option> <option value="1901">1901</option> <option value="1902">1902</option> <option value="1903">1903</option> <option value="1904">1904</option> <option value="1905">1905</option> <option value="1906">1906</option> <option value="1907">1907</option>........................
<option value="2014">2014</option> </select> </li><li><label for="profile_birthdate_2i">Month</label><select id="profile_birthdate_2i" name="profile[birthdate(2i)]"> <option value="1">114</option> <option value="2">97</option> <option value="3">110</option> <option value="4">115</option> <option value="5">108</option> <option value="6">97</option> <option value="7">116</option> <option value="8">105</option> <option value="9">111</option> <option value="10">110</option> <option value="11">32</option> <option value="12">109</option> </select> </li><li><label for="profile_birthdate_3i">Day</label><select id="profile_birthdate_3i" name="profile[birthdate(3i)]"> <option value="1">1</option> <option value="2">2</option> .......................... <option value="30">30</option> <option value="31">31</option> </select>plz have a look at year field (why ended at 2014?) and month (very strange - digits instead month names) :(
Comments
-
Hi, could you tell me plz - why on code
- semantic_form_for :profile, :html => { :method => :put }, :url => update_profile_path do |form|e
- form.inputs doe
= form.error_messagese e
= form.input :female, :as => :select, :collection => [["Male", false], ["Female", true]]e
= form.input :birthdate, :as => :date, :start_year => 1900= form.input :timezone, :as=> :time_zone
e
- form.buttons doe
= form.commit_button "Save"formtastic renders
<li class="date required" id="profile_birthdate_input"><fieldset><legend><span class="label">Birthdate<abbr title="required">*</abbr></span></legend><ol><li><label for="profile_birthdate_1i">Year</label><select id="profile_birthdate_1i" name="profile[birthdate(1i)]"> <option value="1900">1900</option> <option value="1901">1901</option> <option value="1902">1902</option> <option value="1903">1903</option> <option value="1904">1904</option> <option value="1905">1905</option> <option value="1906">1906</option> <option value="1907">1907</option>........................
<option value="2014">2014</option> </select> </li><li><label for="profile_birthdate_2i">Month</label><select id="profile_birthdate_2i" name="profile[birthdate(2i)]"> <option value="1">114</option> <option value="2">97</option> <option value="3">110</option> <option value="4">115</option> <option value="5">108</option> <option value="6">97</option> <option value="7">116</option> <option value="8">105</option> <option value="9">111</option> <option value="10">110</option> <option value="11">32</option> <option value="12">109</option> </select> </li><li><label for="profile_birthdate_3i">Day</label><select id="profile_birthdate_3i" name="profile[birthdate(3i)]"> <option value="1">1</option> <option value="2">2</option> .......................... <option value="30">30</option> <option value="31">31</option> </select>plz have a look at year field (why ended at 2014?) and month (very strange - digits instead month names) :(
Comments
Question 1: "Why ended at 2014?"
You can adjust this using Rails core options (e.g. :end_year):
http://railsapi.com/doc/rails-v2.3.4/classes/ActionView/Helpers/DateHelper.html#M005680
Question 2: Digits instead of month names...
- Passing this ball to Justin, I never seen such behavior and don't really got a qualified guess why right now. =S
-
2 comments Created about 1 month ago by grimen! next patchx@justinxIf :collection is set, select should always be default for enum/string-columnsfor 1.0x...makes more sense - text field for a collection of values (e.g. if enum is stored as a string)
Comments
-
2 comments Created about 1 month ago by grimen! next patchxfor 1.0xLocalized titles don't work for the nested forms casei18nx...it seems forgot this single case: inputs_for_nested_attributes
Comments
-
Comments
justinfrench
Sun Nov 22 20:37:03 -0800 2009
| link
I'm 99%b certain this will fail now that I've addressed an issue with the specs which were masking the previous bug (and this bug ;)). See http://github.com/justinfrench/formtastic/commit/8fb11e177a3ecc0d0847ca8fbc83f4caf95544fd
justinfrench
Sun Nov 22 20:39:24 -0800 2009
| link
So, we just need to find a way for this that actually works. I tried your version, and also template.content_tag, both failed. I've reverted it back to the old hand-coded HTML string for now, so this isn't super critical, it's just a refactor/clean-up for 1.0.
Weird...I didn't write any specs because I didn't know how to spec it and also I thought that would work hands down. Well the old string version is okay I guess; I was just doing the content_tag while I was on it...the I18n stuff was the important change.
justinfrench
Sun Nov 22 21:40:57 -0800 2009
| link
Closing,,,
-
8 comments Created about 1 month ago by pupenoactive_support or activesupport! next patchxI'm not sure if this is an issue. I've just built Formtastic 0.9.2 and when installing it I've got this message:
formtastic requires active_support (>= 2.3.0, runtime)
I do have activesupport: 2.3.4, 2.2.2 and 1.4.4. Is Formtastic expecting active_support instead of activesupport? What am I missing?
Thanks.
Comments
justinfrench
Sat Nov 21 17:51:35 -0800 2009
| link
Are you seeing this error running specs, or running the code in your app? Very strange.
I saw it when installing Formtastic this way:
$ sudo gem install formtastic ERROR: Error installing formtastic: formtastic requires active_support (>= 2.3.0, runtime)and also this way:
$ sudo gem install pkg/formtastic-0.9.2.gem ERROR: Error installing pkg/formtastic-0.9.2.gem: formtastic requires active_support (>= 2.3.0, runtime)BTW, now that I know there's a Google Groups, I asked there.
This is a bug, I messed up the gem dependency references in jeweler gemspec definition (Rakefile).
Now - incorrect:
s.add_dependency 'active_support', '>= 2.3.0'
s.add_dependency 'action_controller', '>= 2.3.0'
s.add_dependency 'action_view', '>= 2.3.0'Correct:
s.add_dependency 'activesupport', '>= 2.3.0'
s.add_dependency 'actionpack', '>= 2.3.0'Patch on the way. =P
Cool. Thanks. Will you generate another gem or should I install from source?
Backup-solution until there's a live one:
With jeweler:
cd /tmp git clone git://github.com/justinfrench/formtastic.git cd formtastic *doing the edit in Rakefile* rake gemspec && rake build && rake install
@pupeno: Good to hear it worked out.
Patch...see:
http://github.com/grimen/formtastic/commit/b2bdc2d8fa661e11306fe8e7ce48222f6beb72e0
justinfrench
Sun Nov 22 21:40:42 -0800 2009
| link
Closing, the 093 gem should resolve it.
-
Formtastic causes div class="fieldWithErrors" to not appear when using form_for
15 comments Created about 1 month ago by pupenoIn a Rails project where I am including the Formtastic gem I have the following non-Formtastic form:
<% form_for(@weight) do |f| %>
<%= f.error_messages %> <%= f.label :weight %>: <%= f.text_field :weight, :size => 5 %> kg. <%= f.submit "Add weight" %> <%= f.error_message_on :weight %> <% end %>which renders to
Weight: kg.
but when I cause a validation error (weight is required) I don't get the proper div class="fieldWithErrors" wrapper. I get this:
<h2>1 error prohibited this weight from being saved</h2> <p>There were problems with the following fields:</p> <ul><li>Weight can't be blank</li></ul>Weight: kg.
can't be blank
Just for reference I should have gotten this:
<h2>1 error prohibited this weight from being saved</h2> <p>There were problems with the following fields:</p> <ul><li>Weight can't be blank</li></ul>Weight: kg. can't be blank
If I use semantic_form_for I get the same behavior.
I originally asked about this on Stack Overflow where you can find some more details: http://stackoverflow.com/questions/747220/rails-validation-and-fieldwitherrors-wrapping-select-tags
Comments
I'm like 95% sure this works if you just update to current gem version. I saw you asked about this back in April at Stackoverflow, and at that time Formtastic didn't respect this. I patched this myself, so I'm aware of this used to be a problem.
grimen, I'm running the latest one installed by gem install today. Should I get an even more recent one? How?
BTW, on April I wasn't doing any Rails, so it must have been someone else.
The patch was included in 0.2.5+ version of the gem. I think you should upgrade either way; FOrmtastic is under heavy development and there been plenty of bug fixes since 0.2.4 - should not break anything.
Here you got the patch:
http://github.com/grimen/formtastic/commit/2b81d9af385dadf8b37dc14f387afe3d43e4958a
grimen, can you confirm the bug is present in the current release but not in the development branch?
It's in 0.2.5+, I'm 100% sure. But I still suggest 0.9.2.
Oh, the reason I was picking an old one is because I was using justinfrench-formtastic instead of formtastic from gemcutter.
justinfrench
Sat Nov 21 17:49:36 -0800 2009
| link
Pupeno, the gem is now on Gemcutter, so you'll need to add that as a source. If you're still having trouble, please have a chat on the google group.
I had gemcutter on my sources but I was installing justinfrench-formtastic instead of formtastic.
Thanks.
Ok, with formtastic 0.9.2 it's working fine as long as I use form_for. If I use semantic_form_for and use the form_for methods inside, I get the broken behavior (not sure if this is something you'd consider a bug or just the current behavior).
It's the expected behavior for Formtastic - but it's not interfering with form_for.
justinfrench
Tue Dec 01 12:50:53 -0800 2009
| link
pupeno, instead of the div wrapper that Rails uses (which can cause all sorts of CSS positioning issues and limitations, we remove that wrapper and add an "error" class to the wrapper around the input, which is better because it means you can actually style the whole li block, or the label, or anything else associated with the error.
-
6 comments Created about 1 month ago by grimen! next patchx@justinxInvalid DOM IDsfor 1.0xNot sure what this does in practice, but I'm 99% sure a numeric value only is not a valid XHTML class:
li_options = value_as_class ? { :class => value.to_s.downcase } : {}Makes Nokogiri XML parser to puke too...
A prefix would solve this, but I'm not sure if that would mess upp things. Specs seems to pass with a small fix, but anyway.
Comments
This line seems to be invalid as well:
output_buffer.should_not have_tag('form fieldset.inputs #post[author]_1_login_input')
I dont' get that one either. Justin?
justinfrench
Sat Nov 21 17:56:16 -0800 2009
| link
José added that in, and I believe it was there primarily for an array of string values or similar. It's a good idea, but obviously the onus is on the author to make sure they only use it when the values are suited as class names, rather than the onus being on Formtastic to ensure validity.
We basically need to sanitize the strings, but I'm not in that much of a hurry :)
Without valid XHTML Nokogiri won't work, so migrating to the newer rspec matchers won't be a good idea then. I do feel that valid XHTML should be a high priority goal though; #post[author]_1_login_input is not a valid DOM ID for sure:
Should match:
[A-Za-z][-A-Za-z0-9_:.]+
Replacing dependency rspec_hpricot_matchers (Hpricot) with rspec_tag_matchers (Nokogiri); specs runs faster, and rspec_hpricot_matchers was not really maintained anymore + Nokogiri is more live project. Also fixed generation of invalid DOM for radio_input/check_boxes input types. Closed by ca12563.
justinfrench
Wed Dec 02 01:37:32 -0800 2009
| link
pulled in, closing.
-
internal: Generic instance-methods => class-methods?
1 comment Created about 1 month ago by grimenMany of the private/protected methods makes more sence as class methods. Maybe a subject for your refactoring Justin?
Comments
justinfrench
Sat Nov 21 17:53:30 -0800 2009
| link
Yeah, it's not in the immediate work I was doing, but there is going to be some HEAVY shifting around post 1.0 :)
Closing this for now though.
-
form inputs not wrapped in <ol> when using individual form.input
3 comments Created about 1 month ago by bitzestyWhen you create a form and do not use a form.inputs block the inputs from form.input are not wrapped by a
<ol>tag. I'm not sure if this is done by design, but I would have expected the form to wrap the inputs regardless how they where declared - if this is not possible then a note in the docs might be in order.example form, where ol is not generated:
<% semantic_form_for @user_session, :url => user_session_path do |form| %> <%= form.input :login, :label => true %> <%= form.input :password, :label => true %> <% form.buttons do %> <%= form.commit_button t(:sign_in) %> <% end %> <% end %>Comments
justinfrench
Sat Nov 21 05:35:48 -0800 2009
| link
That's why the inputs block is provided, to create those fieldset/ol wrappings. The DSL still works if you don't provided it because an LI tag is still valid outside of an OL wrapping, and fields are okay outside of fieldsets.
As for the documentation, the examples all (should) use the inputs block, so… I'm closing this.
-
Hi,
I would just like to post a suggestion because it happens many times in my code and I think on others people code as well.
Having something like a user belongs_to role. In new.html.erb using formtastic will have something like<%= f.input :role %>
that will generate a select list with all available roles.
But now let's say that both admin and supervisor are able to create users. But if, in our spec, a supervisor is able to create only users with operational role we will need something like:<% if @user.admin? %>
<%= f.input :role %>
<% elsif @user.supervisor? %>
<% operational = Role.find_by_name('operational').id %>
<%= f.input :role_id, :as => :hidden, :value => operational %>
<% end %>But now I have no way to show to the user that the Role of the User he is creating is 'operational'.
My suggestion is that we should be able to do something like:<%= f.input :role, :labelize => { :when => @user.supervisor?, :with { :value => Role.find_by_name('operational').id, :display => Role.find_by_name('operational').name } } %>
and this piece of code would generate an li tag with
hidden input that would pass the value to the controller
label (just like when we do <%= f.input :role %> )
label that shows the name of the role
This issue happened to me several times in my projects because we have a constant concern in showing to the user the details of the object he is creating or updating even if he doesn't have permission to change it.
What do you think?
Cheers
Comments
justinfrench
Sat Nov 21 05:38:35 -0800 2009
| link
I don't think this is a common case for which Formtastic should provide a solution sorry. Besides, I actually find your first example with the if...elsif...end far more readible. Closing this.
Hi,
I understand that it can be more readable on the if elsif approach but it doesn't show the role on the page in the first example, it only puts the role hidden.
Even if it sticks with the if elsif approach don't you think that it should be an "input" type label just to show to the user what he is currently doing like:
<% if @user.admin? %>
<%= f.input :role %>
<% elsif @user.supervisor? %>
<% operational = Role.find_by_name('operational').id %>
<%= f.input :role_id, :as => :label, :value => operational %>
<% end %>Notice the change on :as => :label
It's just a suggestion, I will make a fork for me anyway and I think it's a good approach because altough the user can't change the input it's good practice that the user should see the data.
Greetings
justinfrench
Sat Nov 21 17:46:37 -0800 2009
| link
Ok, I think I better understand what you want now. You want the value to be editable by some people and not by others. For those that can't edit the data, we should display the value that would normally have been shown as the select option. Correct?
justinfrench
Mon Nov 23 01:58:54 -0800 2009
| link
(the original poster confirmed this via a direct message)
justinfrench
Mon Nov 23 02:00:00 -0800 2009
| link
My preferred method is to render as a :string with a disabled attribute and then use CSS to alter the appearance of the text field to look like plain text (remove the border, etc).
<%= f.input :ranking, :as => :string, :required => false, :input_html => { :disabled => true, :value => @post.ranking } %>Closing this.
-
12 comments Created about 1 month ago by Rio517! next patchx@justinx:selected option for :check_boxesfor 1.0xHi,
I has a small feature request. I was hoping you could add a :selected option for inputs :as => :check_boxes. Ideally, you could pass in a single value or an array, so that one might set multiple default selected checkboxes.
Thanks!
Comments
justinfrench
Sat Nov 21 05:39:21 -0800 2009
| link
Yup, good idea.
Additions:
- :selected option should be available for:
select,radio,boolean,check_boxes,time_zone(partial), country :selected should accept multiple values for: select (with :multiple => true), check_boxes
Any weird assumptions, or did I forgot any cases?
justinfrench
Tue Nov 24 17:13:02 -0800 2009
| link
Yes, all correct.
Part 4, see:
http://github.com/grimen/formtastic/commit/4d94fb2726fded0dfe0160bc0839991eb40f8fda
I'll not do the country input type now, as it's a bit unclear how that works - 3rd party. Justin, what's ur thoughts on this?
This issue is "sort of" done, but I'll leave it up to you Justin to club that. Boink-Boink! =)
Added support for this for date/time inputs too, see:
http://github.com/grimen/formtastic/commit/2e641c2ad51e1ca0d4a9b7ab2b14bad5b961fd8a
justinfrench
Tue Dec 01 03:00:23 -0800 2009
| link
Pulled in, will be in next patch.
justinfrench
Tue Dec 01 12:47:40 -0800 2009
| link
Awesome work!
- :selected option should be available for:
-
4 comments Created about 1 month ago by mrinterwebUndefined Method semantic_form_fordocxI just got that error and was trying to figure out how to fix it.
I saw:
http://groups.google.com.au/group/formtastic/browse_thread/thread/a90fe1b7224371ffThat helped me out. I was just wondering if you could update your readme file so others don't get hung up on this.
All I had to do to get it working in my rails project was to add this to environment.rb:
config.gem 'formtastic', :source => 'http://gemcutter.org'Comments
My opinion that this is way too much of a human factor to add to README, but I would suggest adding a paragraph to the FAQ wiki page.
mrinterweb
Fri Nov 20 17:20:06 -0800 2009
| link
Thanks for the advice. I just added a quick blurb to the tutorial wiki page.
Cool, I was looking into the discussion and saw the config.plugins stuff...the one above do fit in the README, like so:
http://github.com/grimen/is_visitable/blob/master/README.textile
Something like that?
justinfrench
Sat Nov 21 05:41:37 -0800 2009
| link
Closing.
-
f.inputs can cause double rendering if output on accident
1 comment Created about 1 month ago by thecypher<% semantic_form_for @model do |f| %> <%= f.inputs :name => "My Inputs" %> <%= f.input :field %> <% end %>This causes the form to be double rendered. Now I know what you're thinking, how could one be so silly to use <%= and then indent the next line? Well in my particular case I am using HAML, so the error is much more subtle. Haml version below..
- semantic_form_for @model do |f| - f.inputs :name => "My Inputs" = f.input :fieldI realize this is user error, but perhaps this case could be detected and an error reported?
Comments
justinfrench
Sat Nov 21 05:43:41 -0800 2009
| link
There's no way that I know of to catch this. The damage is done as soon as the = is read, as far as I can tell. Closing, will gladly accept magical patches :)
-
11 comments Created about 1 month ago by kjeldahl! next patchxSelect input with group_by fails if association name is not a class namefor 1.0xI have the following:
class Project belongs_to :company belongs_to :parent, :class_name => 'Project', :foreign_key => 'parent_id' has_many :children, :class_name => 'Project', :foreign_key => 'parent_id' end class Company has_many :projects endIn a form for the project I have
- semantic_form_for @project do |form| - form.inputs :name => 'Project' do =form.input :parent, :group_by => :companyAnd it fails with
method_missing: undefined method parents for "#<Company:0x104115288>":Company)Which is cause by the method.to_s.pluralize in the call to grouped_collection_select. The correct method to call would be projects.
I will try and make a patch for looking up the correct method.
Comments
I have created a patch here: http://github.com/kjeldahl/formtastic/commit/3f66d9e07b16bca5a1ca8a08bca171e4097b250a
jeroenvandijk
Fri Nov 20 07:20:42 -0800 2009
| link
I have implemented the original :group_by option and I didn't have the above requirement, but I agree that it should just work.
The patch looks good, but it would be nice if you could write some specs that fail without your patch and pass with your code to prevent regression later on.
justinfrench
Sat Nov 21 05:44:32 -0800 2009
| link
kjeldahl, please add a spec to your fork so I can pull this in and release it straight away!
I have just pushed the spec.
I added the self association on Post so it now belongs to a main_post and has_many sub_posts. Please have a look at the mocking and stubbing to ensure that the test is actually valid.
I have not yet added a spec the the third case mentioned in the patch. Primarily because it wasn't an issue for me, so perhaps the code should just be removed?
justinfrench
Tue Dec 01 03:02:40 -0800 2009
| link
Great work, will pull in soon, as the patches no longer apply since I pulled in Grimen's marathon of commits. Will work it out.
justinfrench
Tue Dec 01 14:31:34 -0800 2009
| link
Ok, something ain't right with my merge.
meantime:~/dev/formtastic (master)$ spec spec/inputs/select_input_spec.rb
............................................F........................................................................................................1)
Spec::Mocks::MockExpectationError in 'select input for a belongs_to association with :group_by => :author should call author.posts'
/Library/Ruby/Gems/1.8/gems/rspec-1.2.9/lib/spec/mocks/error_generator.rb:64:in__raise': Mock "user" received unexpected message :main_posts with (no args) /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_view/helpers/form_options_helper.rb:388:inoption_groups_from_collection_for_select' (eval):1:inoption_groups_from_collection_for_select' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_view/helpers/form_options_helper.rb:388:inoption_groups_from_collection_for_select' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_view/helpers/form_options_helper.rb:385:ineach' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_view/helpers/form_options_helper.rb:385:ininject' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_view/helpers/form_options_helper.rb:385:inoption_groups_from_collection_for_select' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_view/helpers/form_options_helper.rb:552:into_grouped_collection_select_tag' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_view/helpers/form_options_helper.rb:214:ingrouped_collection_select' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_view/helpers/form_options_helper.rb:592:ingrouped_collection_select' ./spec/inputs/select_input_spec.rb:112: /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_view/helpers/form_helper.rb:490:infields_for' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_view/helpers/form_helper.rb:282:inform_for' ./spec/inputs/select_input_spec.rb:111:Spec around 111:
describe "for a belongs_to association with :group_by => :author" do it "should call author.posts" do [@freds_post].each { |post| post.stub!(:to_label).and_return("Post - #{post.id}") } @fred.should_receive(:posts) semantic_form_for(@new_post) do |builder| concat(builder.input(:main_post, :as => :select, :group_by => :author ) ) end end endAny ideas?
Also, why did you put these in spec_helper?
@new_post.should_receive(:publish_at=).any_number_of_times @new_post.should_receive(:title=).any_number_of_timesI think it was me adding those last 2 lines in the spec_helper. My reason was: I don't like mocking/stubbing. Sometimes totally overkill actually. Remove 'em if you get the specs to run. ;)
justinfrench
Tue Dec 01 23:27:32 -0800 2009
| link
Ok, found the issue(s), have wrestled with git and pulled this bad boy in!
http://github.com/justinfrench/formtastic/commit/9c1daba14daea0d56d309d64322b87d570af832c
http://github.com/justinfrench/formtastic/commit/7a2ef48dfffc69875debd094522ee967ad2640d4Closing, but feel free to review!
-
7 comments Created about 1 month ago by activestylusTranslation arrays not parsed correctlyfor 1.0xWhen using a collection we get these weird id numbers as values instead of strings
Translation file
en:
titles:- Mr - Ms - Drf.input :title, :as=>:select, :collection=> I18n.t('titles')
This will give me options that look like this
Mr
Ms
DrClearly not what I was looking for - maybe to_s needs to be called somewhere?
Comments
activestylus
Thu Nov 19 05:05:29 -0800 2009
| link
Damn that comment just ate my code - all you need to know is that the option values are usually integers instead of the desired string
Sorry, I don't understand your question. Could you clearify what you expect? Also, I would suggest putting the code in a gist or pastie.
activestylus
Thu Nov 19 06:16:29 -0800 2009
| link
This should do it:
Sorry, I can't reproduce this. Can't get the spec to fail even with loading a raw YAML file. Either we need a failing spec or a physical proof (see http://github.com/grimen/test_app) - or it'll be closed.
Data:
en: titles: - Mr - Ms - DrSpec (one of them, all different flavors passed)
describe "from I18n lookup" do before do translations = File.open(File.join(File.dirname(__FILE__), *%w[.. data en.yml])) { |file| YAML.load(file) } ::I18n.backend.store_translations :en, ::HashWithIndifferentAccess.new(translations)[:en] semantic_form_for(@new_post) do |builder| concat(builder.input(:title, :as => :select, :collection => ::I18n.t(:titles))) end end it "should load option values correctly" do output_buffer.should have_tag('form li select option', 'Mr') output_buffer.should have_tag('form li select option', 'Ms') output_buffer.should have_tag('form li select option', 'Dr') end end
activestylus
Fri Nov 27 18:25:47 -0800 2009
| link
I spoke with our team about this and it turns out the problem is related to our use of Globalize. I tested out a fresh app and did not have this issue but as soon as I installed Globalize I got those weird integers.
As a temporary fix I just do something like this:
:collection => I18n.translate('titles').map(&:to_s)
Which gives the desired result.
OK, great. I had major issues with Globalize and GLobalize 2, so I dropped it for good. Doin fine without it - there are thinner alternatives that work very well for me: http://github.com/janne/model_translations
Closing this.
-
4 comments Created about 1 month ago by grimen! next patchxfor 1.0xFormtastic::I18n modulei18nxJustin, when now when you doing the big refactor of the lib I would suggest to introduce a new module: ::Formtastic::I18n. There's some redundant code that could be DRYed up with ::Formtastic::I18n#translate() method, and storing default string values in constants within the same module. I noticed Authlogic (and other popular plugins) follow this pattern as well.
Before:
::I18n.t(:yes, :default => 'Yes', :scope => [:formtastic])
After:
I18n.t(:yes)
Stating the obvious: Without "::" it'll be same as ::Formtastic::I18n.t(:yes) if called within the Formtastic namespace.
Comments
Of course, I could do this (not a big change) but will probably wait for your refactoring.
justinfrench
Sat Nov 21 05:49:50 -0800 2009
| link
My refactoring got shelved again, go for it :)
-
5 comments Created about 1 month ago by justinfrench! next patchxDate/time inputs could default to "now" (like Rails does) if the value is nilfor 1.0xComments
I got something that "should" work here, but RSpec says it's not. Please feel free to review what's up with that. 98-100% complete that is.
http://github.com/grimen/formtastic/commit/59d844d5aa708a874feb8c49071c5e5b89bff1ad
To clearify: There are 3 failing specs that should not fail, but they do because form.object/@object is set to nil for some reason... =P
-
5 comments Created about 1 month ago by grimenreview: rspec_hpricot_matchers upgrade@grimenxIt seems Formtastic depend on a Rubyforge-library that been dead since early 2008 (ouch). There's a fork of that project that lives on GitHub that been very active. Maybe should be considered to try that one out; seems like it's faster as well as it replaced Hpricot for Nokogiri (and the spec suit is slow as f*ck now so...). Seems it was polished a lot, added helpers etc.
Comments
justinfrench
Wed Nov 18 15:11:57 -0800 2009
| link
Go for it!
Mailed the dude behind, trying to get him to claim the project and get it on gemcutter. Might take some time, but no hurry really.
Update: I forked that project as "rspec_tag_matchers" and it now lives on Gemcutter after some modifications. On Ruby 1.8.7 specs run 4 seconds faster. B) For some reason specs run slower on Ruby 1.9 (wierd), but "rspec_tag_matchers" is 1-2 seconds faster.
Note: Hey, in 4 seconds you can run and push the coffee machine button (I noticed)! ;)
-
It's impossible to pass a value to a hidden field even if we specify something like:
<%= f.input :object_id, :as => :hidden, :input_html => {:value => @object.id} %>
By the way,
Great work on the plugin! It's becoming really useful!
Comments
This works:
<%= f.input :object_id, :as => :hidden, :value => @object.id %>
...but I can agree that this is a bit inconsistent. What do you think Justin?
See:
http://github.com/grimen/formtastic/commit/f4964b4c248722d5d98723d51d56c7e04425dbdb
I think this should be possible to set the value using html_options. My argument is that it's confusing that only hidden_input lacks the html_options hash just because it's not a visible input.
justinfrench
Wed Nov 18 15:09:47 -0800 2009
| link
So you've made the API the same as, say, string input?
Uhm, not sure what you mean, but see the spec. The only input_html-option that works is :value - so that people don't get stuck like jduarte did above. This might need a bit more reflection maybe, but I just pushed this so we got something physical (digital). =)
jduarte said:
It's a little bit off-topic but since we're talking of hidden inputs.
For me it doesn't make sense an hidden input being wrapped in a li tag by default.
I think it can mess up uneccessarely with the CSS.
What do you think?Yes, maybe hidden fields should be placed in a hidden div in the form header just like Rails does this. Should be straight-forward to do with the content_for helper. Makes sense to me.
justinfrench
Sat Nov 21 05:49:10 -0800 2009
| link
Hidden fields cannot be rendered without the LI wrapper because it's invalid to have child elements of an OL or UL that are not an LI, which is why we render them within an LI, and why the default stylesheets supplied with formtastic hide li.hidden inputs. Closing.
But did you reflect on my last suggestion? Se how the security token gets attached to a Rails form. My suggestion would be to stack them all like that.
justinfrench
Sat Nov 21 17:45:03 -0800 2009
| link
Ah, I missed the content_for bit of your message. Absolutely, feel free to have a play!
-
4 comments Created about 1 month ago by grimen! next patchxdocxMention "form generator" on gem installation?for 1.0xNow mentions the "formtastic generator" on install, but it would make sense to mention the form generator as well to give newbies a smooth first ride. Agree?
Comments
justinfrench
Tue Nov 17 20:06:52 -0800 2009
| link
Agreed.
-
When there is a (select) field that is required, it should have include_blank => false by default.
Comments
justinfrench
Mon Nov 16 12:04:16 -0800 2009
| link
I don't agree. Just because an field is required, that doesn't mean that the form should make a default choice for you (typically the first option). By having a blank default, you can ensure that the user actually makes a choice.
Ultimately, this comes down to a mixture of personal preference and a case-by-case basis. You suggestion is not always appropriate, neither is the current implementation, which is why we added a global preference and an option into the DSL on a field-by-field basis.
I'm not particularly excited about adding a further configuration, closing for now.
-
2 comments Created about 1 month ago by justinfrenchfor 1.0xi18nxbutton texts are not scoped under actionsnot surexwant to make sure we don't lose this patch/thread until we resolve it one way or another
http://github.com/DarkTatka/formtastic/commit/5902bbacc02b01f96409c8b2ddec2ce0374765bd
Comments
-
5 comments Created about 1 month ago by kbrock! next patchxsupport ranges for collectionsfor 1.0xRails supports ranges as collection values for input fields.
Could you also support them (aka just pass them through)
Thanks
http://github.com/kbrock/formtastic/commit/e9a40dafcb2950d9b9ecd8dc2b8d2a072ea6d6f3
Comments
I noticed this as well, but not sure how many use-cases there are except for integer ranges - and that is very easy to implement with (a..b).to_a or [*a..b], so I never thought about it further myself. The question we need to ask now is: How many use cases we got for ranges except for range of Integers? If there are a few, and they all can be implemented in a way that makes sense, you get my vote on this one.
justinfrench
Sat Nov 14 02:13:08 -0800 2009
| link
Doesn't seem like a big deal to support this, I'll gladly pull this in when there's some specs!
Added support explicit values of type Range for the :collection option of the select input, e.g. form.input :rating, :as => :select, :collection => 1..5. Added specs for both ranges, and explicit array values which was lacking. Closed by 440bd2d.
-
Decimal data types calculate incorrect length
3 comments Created about 1 month ago by kbrockIf I have a field with precision 5,3: 2 digits to the left of the decimal place and 3 to the right.
e.g.: 99.999That is 6 characters long. (5 digits and 1 decimal place)
Please add support for decimals
http://github.com/kbrock/formtastic/commit/6c3baa7f2e88ca2674aeb39d2ccdca406cdbea94
Thanks
Comments
justinfrench
Sat Nov 14 02:31:02 -0800 2009
| link
Would've loved some specs for this before applying, but I'm in a good mood and really want to clean up the forkqueue a bit, so you might get lucky ;)
justinfrench
Sat Nov 14 03:29:27 -0800 2009
| link
Hmmm, in your patch, this seems to be only applied if you have :as => :string, because the code you wrote is skipped for :as => :numeric, which would be the default type for a decimal column. Having a play...
justinfrench
Sat Nov 14 03:42:03 -0800 2009
| link
I tried to write some specs for this, and I encountered two problems. The code supplied in the patch was bypassed for numeric inputs (which is the default for a decimal field), so in attempting to correct this, I realised we had some pretty good reason not to apply sizes and limits for numeric inputs, as discussed in issue #19.
I'm not smart enough to know I've covered off all the considerations necessary for all databases and number-like column types, so my proposed solution right now is that you use :as => :numeric, which will not apply a size or maxlength.
Closing this for now, please feel free to re-open if you wish to discuss, or have a solid patch with coverage.
-
4 comments Created about 1 month ago by grimen@grimenxfor 1.xx:with => <form_helper_method>not surexComments
Justin, if I spec and implement this - will it be of interest yet?
justinfrench
Wed Nov 18 01:24:45 -0800 2009
| link
I really don't want to open the "custom inputs" issue right now, in any shape or form :)
OK, I maybe do this in a experimental-branch so we can play with it.
After some code experiments: Closing this in favor for http://github.com/justinfrench/formtastic/issues/#issue/46
This one (:with) adds too much complexity, and can without complexity be solved using the "issue-46-way".
-
1 comment Created about 1 month ago by justinfrench:selected option works for :select but not for :radio collectionsfor 1.0x -
:collection should accept an array of arrays
4 comments Created about 1 month ago by justinfrenchRails' built-in select can accept an array of arrays [[text, value], [text, value]], pretty sure :collection can't, which means you have to write some pretty crazy code to convert one:
f.input :parent, :as => :select, :collection =>
nested_set_options.inject({}) { |result, element| result[element.last]
= element.first; result }This came up in the google group with someone using nested_set_options() as part of http://github.com/collectiveidea/awesome_nested_set
Comments
Hmm...this works for me:
= form.input :animals, :as => :select, :collection => [["Duck", 1], ["Horse", 2]]
=>
(Grrrr....I hate GitHub the markup not accepting HTML tags in PRE)
justinfrench
Tue Nov 10 13:36:12 -0800 2009
| link
Cool, not a bug then!
Instead of pre, markdown needs four spaces at the beginning of a code line to turn it into a code block, FYI
-
In the code examples:
inputs => form.inputs
buttons => form.buttons
Comments
justinfrench
Tue Nov 10 02:43:43 -0800 2009
| link
fixed in a8e2f2e
-
5 comments Created about 1 month ago by dyohi! next patchxuninitialized constant Formtastic::SemanticFormBuilder::I18nfor 1.0xI am getting the following error
uninitialized constant Formtastic::SemanticFormBuilder::I18n
Extracted source (around line #3):
1: <% field_set_tag("Personal Information") do %>
2: <% semantic_remote_form_for(@tabdata, :url=>{:action=>:personal_update, :id=>params[:id], :intake_id=>params[:intake_id]}) do |f| %>
3: <%= f.input(:aliases, :label=>"Aliases: ") %>
4: <% end # semantic_remote_form_for %>
5: <% end # field_set_tag("Personal Information") %>Comments
Stack trace? The one provided is not enough. (Note: I've used ::I18n instead of I18n in the most common places so that this should never ever happen, but older I18n code don't. Should not be an issue with Ruby 1.8.x though...)
I believe we can make this never happen quite easily with just using ::I18n everywhere, but I'm not sure how to spec this - even in Ruby 1.9 where this could happen sometimes because Ruby 1.9 sometimes do this ind of namespace assumptions. In other words: I guess we have to skip specs for this one. Patch in progress... =)
Adding "::" to I18n and Formtastic constants to avoid namespace issues (especially a issue in Ruby 1.9). Closed by e3c200a.
-
option to turn off inline error message
4 comments Created about 1 month ago by dwilkieThere is no way to suppress the output of an error message e.g
= f.input :email. :inline_error => falseComments
justinfrench
Thu Nov 05 22:29:35 -0800 2009
| link
You can turn it off on a global level by omitting it from the inline_order configuration, at a model level by not adding error messages, or if none of those appeal, I'd recommend to simply hide the errors at a presentational level with CSS, eg:
form.formtastic #article_title_input ul.errors { display:none; }I'm closing this issue for now, let me know if you believe none of these options are appropriate.
Consider the case of a login form say using Authlogic. I don't want to display the actual error message for the form fields username or password because this opens up a security floor. Instead I want to display a generic error message. e.g. "username or password incorrect".
In this case I don't want to turn the error messages off on a global level. This will affect all other forms in the application where I need the errors displayed.
On a model level I would have to override the "errors" method and remove the messages on username and password. This is also not ideal. And I think this is more of a view issue anyway.
Lastly as you mentioned, I could simply hide the error on a presentational level as in your example above. However this will still show the error messages in the source, again opening up the security hole.
What do you think?
saturnflyer
Fri Nov 06 09:10:19 -0800 2009
| link
+1 dwilkie
justinfrench
Mon Nov 09 13:07:17 -0800 2009
| link
Ok, that's a pretty special case, but I agree with you I guess. Thinking about it!
-
10 comments Created about 1 month ago by grimen! next patchxfeature suggestion: DRYer fieldset legendsfor 1.0x- inputs :title => "My little fieldset" do = input :name
...with an equivalent way:
- inputs "My little fieldset" do = input :title
Thoughts?
Comments
...an the I18n-way should work the same way of course:
- inputs :some_fieldset_title do = input :title
It looks like this should work by the look of the code. Should only be triggered if block is given. Did I miss something though?
justinfrench
Thu Nov 05 17:28:05 -0800 2009
| link
I'm not following. What's the relationship between...
inputs :title => "fieldset legend text goes here"and...
input :titleThe latter renders an input for the title attribute on the model, the former adds a legend to the fieldset.
I think you meant to type:
input :namein your example, yes?
If so, I'm following ;)
Ouch, yes - I blame the tiny GitHub comment box. =) Removed :title to not cause confusion, fail. Trying again:
- inputs :title => "My little fieldset" do = input :yahoo
...with an equivalent way:
- inputs "My little fieldset" do = input :yahoo
Tag this one with 1.x, or what's the current consensus?
justinfrench
Sat Nov 14 02:25:47 -0800 2009
| link
Yeah, I'm okay with this, sure. 1.0'd it.
DRYer fieldset legends; check if first inputs block argument is a valid legend - the options (:name/:title) way works still, and got higher priority. Closed by 3cad250.
-
Hi,
with formtastic 0.2.4 there are problem with rendering errors. I have form<% semantic_form_for [@news_article, Comment.new], :url => {:action => "add_comment"} do |form| %> <%= form.error_messages %> <% form.inputs do %> <%= form.input :body, :as => :text, :label => "Comment" %> <% end %> <%= form.buttons %> <% end %>and in news_article_controller
def add_comment @news_article = NewsArticle.find(params[:id]) @comment = @news_article.comments.build(params[:comment]) if @comment.save flash[:notice] = "Successfully saved comment." redirect_to :action => 'show' else redirect_to :action => 'show' end endin Comment model i have
attr_accessible :body validates_presence_of :bodyLooks good, but there are no error messages on commit of empty form :(
Comments
UPD: its the same for inline error messages and standart form.error_messages
huh ... i'm using no rspec :) but i've added flash[:error] before redirect_to :action => 'show' in news_article_controller and see flash, but no error messages. I've checked with disabled css (just to confirm, that there are no problem with css) and still see no committed comment :(
If you clone this:
http://github.com/grimen/test_app
...can you reproduce this if you change the Formtastic to use 0.2.4?
NameError in PostsController#update
undefined local variable or method `template_format' for #<PostsController:0x1039b4f48>
i've changed #{template_format} to erb - works. And messages was shown .... I'll check al my code again
huh ... maybe problem with
semantic_form_for [@news_article, Comment.new]and errors will be displayed for
<% semantic_form_for [Comment.new]???
I didn't quite understand the last reply; could you maybe fork test_app and push the pages so that I can review it visually?
huh ... i've found solution. But let me explain whats was wrong :) I've developed form for using polymorphic associations (http://asciicasts.com/episodes/154-polymorphic-association). and used sentence semantic_form_for [@news_article, Comment.new]. But everytime form rendered - there are new instance of Comment. I've solved it with
<% @comment = Comment.new unless @comment %> <% semantic_form_for [@news_article, @comment], :url => {:action => "add_comment"} do |form| %>Anyway - thanks a lot for your support :)
OK, great. I've had this before some time ago but still didn't catch that by the look; this should maybe go into FAQ - even though it's not Formtastic-related. This is a bit DRYer though:
<% semantic_form_for [@news_article, (@comment || Comment.new)], :url => {:action => "add_comment"} do |form| %>Closing
-
Whenever there is a nested fieldset we get a legend containing a span with a class of "label"
I propose that the same behavior be applied to the top-level legend tags, perhaps with a class of "title", "main" or "top"
This will make the setting of font-sizes a lot easier as span.label inherits normal sizes while you can declare larger fonts on span.title without worrying about the cascade.
Easy enough to tweak - What do you think?
Comments
activestylus
Tue Nov 03 09:29:59 -0800 2009
| link
Nevermind, I figured a way to hack it in the css
-
11 comments Created 2 months ago by aaronchi! next patchx@grimenxWould prefer attribute names not added to input classesnot surexWith formtastic 0.9.1, it seems like the name of the attribute is being added to all of the inputs. This seems very messy to me. It has already caused styling issues in one of my applications where some css selectors have the same value as the name of model attributes.
Isn't it enough to just allow users to override the class using the existing methods? If this was a request, I would suggest adding some kind of a scope to the class name. Like .input-{attribute_name} or something like that to keep it from conflicting with other css selectors
Comments
justinfrench
Wed Oct 28 15:33:17 -0700 2009
| link
Yeah, in retrospect I think that was a mistake. Will review.
Well, removing them completely is not a god way either. I suggest namespacing as a last resort. That is how Validatious handle clashes: v2_blablabla, etc. Could have: attr_title, or similar
justinfrench
Thu Oct 29 13:50:58 -0700 2009
| link
I guess I'm surprised that this would be ultra useful or necessary to people in your average application, especially when:
There's a provision in the DSL for adding classes:
f.input :title, :wrapper_html => { :class => 'foo' }
And there's a provision for providing your own custom inputs to wrap up your own custom logic by subclassing (and we'll get even better support later):
f.input :title, :as => :foo
My understanding is that this would be useful when you're trying to apply the same styling to a bunch of similar inputs with the same method name scattered across a bunch of different models (if it's the same model in multiple places, there's already other hooks to support this).
I just find it hard to believe there's a massive use case for it, but I'd love someone to prove me wrong.
So before we commit to this in 1.0, I want to be sure it's needed.
Discuss :)
I''m sure what I vote for too: -1
Best argument: :wrapper_html => { :class => 'foo' } is not dry, neither beatiful nor obvious code. In the future apps "basic controles" won't be enough, and styling certain fields will be crucial.
by -1, I meant +1 for removing the attributes names ;)
justinfrench
Fri Oct 30 12:47:35 -0700 2009
| link
grimen, I agree that it's not beautiful code, but no one (yet) has shown me why they'd need this class added to every attribute automatically to avoid the ugly code
In all of the form implementations I've seen, the only classes automatically added to the fields or field containers are ones the define the field type (text, password, etc). formtastic already does this.
For all other types of special inputs, it should be up to the user to define since the database isn't a reliable source for metadata anyway. For example, a phone number field could be called home_phone, work_pone, phone, phone_number, number etc... and then all of those fields would have different classes. What I would probably really want is just to add a phone class to my views or create a subclass for this field type. While :wrapper_html => { :class => 'foo' } may not be 'pretty' it's the same thing as passing a :class => '' option to any content tag in Rails.
Is there an argument for keeping these?
Yes, if you use non-standard inputs that gets styles unobtrusively. That's why I propsed namespaced classes: attr_title, attr_body, ...
Who said :class => is "good"? For people swiched to HAML :class option alread got redundant anyway because it's not DRY. With namespace drawbacks are none, without those calss names drawbacks are a lot of extra code that a smart form builder should generate for you - instead focus on the actual styling than putting classes explicitly on everything. Predictable CSS classes is very powerful, in the same way as method names in Ruby are very predictable. Focus on what's important that is.
justinfrench
Fri Oct 30 13:38:02 -0700 2009
| link
Grimen, I absolutely value your opinion, but I'm going to push you to give me an answer that I like :)
I don't want to argue if :class is good or not. It probably isn't, and I probably shouldn't have brought it up. However, it is a valid option for occasions where a high level grouping is needed. Which brings me to my next point.
I think the occasions where attr_title would be valuable for a designer would be extremely rare. By rare, I mean the chances that you have many disparate models that all have a "title" attribute that all need to be styled the same way in the app, and all of which need to be styled differently to other string inputs (for example).
I want you (or anyone) to give me a concrete example to change my mind. It's not enough for to argue that it's theoretically useful, not is it enough to argue "the drawbacks are none".
Finally, what we're all trying to achieve here is the addition of a new type of class on wrappers that allows certain groups of inputs to behave in a similar way. We're already doing this in the plugin, by defining a new type of input. :string vs :numeric are classic examples. They both render the same markup, with the exception of the class name on the wrapper.
I guess what I'm trying to say is, we already know what the DSL should be:
f.input :home_phone, :as => :phoneThe phone input (a custom input) should contain all logic (class names, markup, etc) for creating that type of input over and over again reliably.
This is actually more useful (IMHO) because it will work for fields that don't have similar attribute names (name vs title, for example).
Show me a concrete example, then we can talk about the appropriate solution, which may indeed be the class names you've proposed.
justinfrench
Mon Nov 09 12:24:51 -0800 2009
| link
killed it (until someone can show me a use case) in df97907
-
7 comments Created 2 months ago by grimen! next patchxdate/time inputs should have label within legendfor 1.0x...for usability/accessability reasons:
<legend><label for="#{id_for_the_first_input}">...</label></legend>Clicking on the label will give focus on the first input.
Comments
justinfrench
Wed Oct 28 14:47:21 -0700 2009
| link
Not convinced it's "correct", but I'll think and look into it.
Btw, I still don't know how to escape HTML in GitHub-issues. =P Got a clue?
Regarding your reply:
Right now if you click the other labels they put focus on fields, but not for date/time-fields. Confused me when I noticed. If it's correct markup-wise - valid (X)HTML - I can't see this be incorrect in another way.
justinfrench
Thu Oct 29 13:34:20 -0700 2009
| link
So as there's already another label on the first select, the questions are...
- can a control have more than one label associated with it?
- can a label be placed inside a legend?
After reading both the HTML 4 and HTML 5 specs, I think the answer to the first is "yes":
"More than one LABEL may be associated with the same control by creating multiple references via the for attribute."
They don't mention anything about what a legend can contain, so it looks like this is a good idea.
A few notes — we already nest a span in the legend and have special code to do all that, so in many ways it'll be a simplification (unless of course you've got your own CSS that makes different assumptions, so we'll need to warn about the change).
Yep, I had that span in mind as well. I noticed some use labels on the error messages as well, but semantically-wise I don't get that - even though usability-wise it's kinda good. Just a note.
Label-issues:
- Inputs with legends as labels now got class "label" on the legend to make the styling of these much easier.
- Inputs with legends as labels now wraps a label instead of a span, and the label is "connected" (with the "for" HTML attribute) to the first of the wrapped inputs - clicking label gives focus to this input. Reasons: Better form accessibility/usability, and is semantically more correct.
- Removed: :as_span-option for the Formtastic label helper - not needed anymore.
Closed by c790638.
-
8 comments Created 2 months ago by robertwahler! next patchxInvalid deprecation warning in commit_button@grimenxI'm getting a deprecation warning in the current master when used in development that looks like a logic error that isn't tested in the spec. The warning doesn't show when running the spec. I'm not using I18n.
DEPRECATION WARNING: Formtastic I18n: Key 'formtastic.save' is now deprecated in favor 'formtastic.update'.. (called from commit_button at /.../plugins/formtastic/rails/../lib/formtastic.rb:306)
Comments
That's because I silence it in test_helper.rb. It's just a warning, and the both keys should still work. If they both don't work, then that's a bug.
robertwahler
Wed Oct 28 09:19:19 -0700 2009
| link
Ah. Thanks. That explains why the warnings don't show up in the spec. I'm not convinced that silence on warnings is a good idea since testing is a good time to see valid warnings.
Both keys do work but why should we have warnings in the default "update" usage of commit_button?
OK, well yea it seems I forgot to check if that key is actually defined in the I18n stored translations - only then throw that warning.
justinfrench
Mon Nov 09 12:32:46 -0800 2009
| link
Grimen, is there a patch for this? Can't spot it in the log or forkqueue.
"yes and no", it's in my head =), but I had a hell of a week with stuff to do so no time. This week is more open though.
justinfrench
Sat Nov 14 03:50:15 -0800 2009
| link
c'mon!!!!
justinfrench
Sun Nov 15 11:50:09 -0800 2009
| link
I've done it my way, by removing the special fallback and the deprecation warning. We're pre-1.0 and I wanted to burn all the deprecated APIs before 1.0 anyway. See b9131dc
-
Hi,
could you tell me plz - is it possible to create radio-buttons with mix with other fields (e.g. textfields) like on disqus avatar page (http://disqus.com/profile/avatar/) like
- radio - textfield - radio - textfield - radio - radio - submit button If it possible - how?Comments
justinfrench
Sun Oct 25 14:46:25 -0700 2009
| link
Hi, these most definitely fall outside of what Formtastic is trying to do.
For stuff like this, you really want to either mix your own HTML/ERB and regular Rails helpers within the form block in your view (like you used to, before Formtastic came along), or if this is something you're doing a lot in your views, you may want to wrap this into a custom input by subclassing Formtastic, which I've discussed on the mailing list.
-
Did some work on trying to make the README more...readable. high-hat + laughs Just experimenting - it's hard to preview how the stuff will look on GitHub (they parse the stuff different from most other Textile-parsers i noticed). Anyway, here it is (plenty of commits, can fix that if I get thumb up):
http://github.com/grimen/formtastic (README.textile)
I think it's much better, but that might be my alter-ego speaking. =)
Comments
justinfrench
Sat Oct 24 22:44:14 -0700 2009
| link
pulled in
-
I'm curious why all methods are public? Some of em only makes sense to Formtastic internally, and should not get exposed, right?
Comments
justinfrench
Mon Oct 26 14:22:47 -0700 2009
| link
Well, at the moment, there's 4 or 5 public methods (which I consider the public API) and the rest are protected. I don't mind the idea that they're changed to private, but I just tried that as an experiment and there was a whole lot of failing specs.
Honestly, I like Chris Wanstrath's recent statement "no more private methods in my projects... we're all grownups".
-
A tiny change would mean the world if one would like to extend your builder a bit
Could you change this line in the helper module methods
options[:builder] = @@builder in
options[:builder] ||= @@builderthis way if I make a class that extends the SemanticFormBuilder I only have to call semantic_form_for(:builder => MyOwnFormBuilder) and not lose all the classes and error proc.
Comments
justinfrench
Sat Oct 24 00:51:39 -0700 2009
| link
The idea is that you set @@builder via the initializer config file, rather than on each form. Are you saying that you need a special builder for just some of the forms in your app, or are you happy to use MyOwnFormBuilder across the app?
DiMarcello
Sat Oct 24 05:29:10 -0700 2009
| link
ok, that's a plan yes, but it still would be nice to do so,
right now i use it on all forms, but i see it happen to make several builders with different outputs (like tables for nested has_many fields).and instead of copy pasting the entire helper method i could just let the new helper method call semantic_form_for(:builder => TableFormBuilder)
justinfrench
Sat Oct 24 16:14:00 -0700 2009
| link
For the moment, I'm not interested in adding in this complexity, tagging with 1.x to revisit when things have settled down.
justinfrench
Wed Dec 02 02:13:20 -0800 2009
| link
-
Hi,
first of al let me thank you for perfect plugin. But, there are some unclear issues for me:
1. Is it possible to use single check box (for example - for license agreement)?
2. Documentation does not contains information about error_messages for form
3. How to set id to form element? For example - to button.Comments
Hi, questions actually belongs to the Google Group - but...
- This is documented. Example: f.input :agree, :as => :boolean
- Justin?
- This is documented.
Inputs:
f.input :name, :input_html => {:id => 'cucumber'}Buttons:
f.commit_button "Shoot", :button_html => {:id => 'shotgun'}- ooh sorry - my fault :(
- can i use something like form.error_messages ?
- thx, deep night make my eyes blind :(
#2. Everything that is possible with Rails core form builder is possible with Formtastic. In this case:
f.errors # => []
f.errors[:base] # => [<non-attribute specific errors (base-errors)>]
f.errors[:title] # => [<"title"-attribute specific errors>]
- This is documented. Example: f.input :agree, :as => :boolean
-
...to match the current I18n API for labels/hints/legends. Might need to revise this a bit later, but most of it could be done now already.
Comments
Consider this done, I'm just doing some view testing as well to be sure.
Bonus: I think I resolved I18n-lookups for non-object references (issue #87). Not 100% sure, but 95% sure that this missing support was what "it was about". ;) I had issues with this myseld when trying to get the new specs to pass. I'll try it that example visually too.
OK, here we go:
http://github.com/grimen/formtastic/commit/8a3e3acaf44f678c9e8beef6627ec2d00e861e04
I accidently merged the changes on top of this commit, but I'm sure that will be alright. If not, I'm off to bed now and fix that when I get some spare time.
P.S. This is kinda huge commit, and there might things you want to review. Just message me och continue this thread.
justinfrench
Sat Oct 24 14:46:21 -0700 2009
| link
I'm still pretty oblivious to i18n stuff, I've pulled this in, perhaps ping Jose see if he can provide feedback.
-
6 comments Created 2 months ago by justinfrenchdate/time inputs don't respect the 'always include a blank' config option! next patchxComments
justinfrench
Fri Oct 23 15:47:32 -0700 2009
| link
I'm wondering why you burned the specs, I thought they're still relevant.
Nah, they are actually extended and placed in a new file:
Date/Time-inputs now respects "always include blank". closed by a6983ab
justinfrench
Fri Oct 23 16:30:10 -0700 2009
| link
Ah, awesome. I've been caught by that quirk on Github many times :)
Pulled, closing.
-
15 comments Created 2 months ago by justinfrench! next patchxProblems with labels on :boolean inputs@grimenxPasted from the google group:
<%= f.input :published, :as => :boolean %>creates the following HTML (indentation mine for readability)
<li id="asset_published_input" class="boolean required published"> <label for="asset_published"> <input type="hidden" value="0" name="asset[published]"/> <input type="checkbox" value="1" name="asset[published]" id="asset_published" checked="checked"/> </label> <label for="asset_published"> Published <abbr title="required">*</abbr> </label> <abbr title="required">*</abbr> </li>Note the double "required" output and the text of the label is not
nested inside the tag containing the checkbox. This is
causing the label text to shift to the right a considerable amount.I see there's a github issue at http://github.com/justinfrench/formtastic/issues#issue/60
that relates to whether or not the text should be inside the label.
Personally, I think it should.Commit d8290cf introduced what I
think is the change that created the issue. I am at a loss, without
spending more time than I have, to find a fix. My quick attempts have
failed.Also note the two label tags.
Comments
Hmm...I'm not sure what the problem is (maybe because of that GitHub trimmed your code - I hate that too). Could you paste the code again using a gist or or pastie?
Too clarify: I don't see any problems in my Formtastic test forms.
ruckus-matte
Wed Oct 21 18:07:02 -0700 2009
| link
grimen, I'm the one that brought this to light. See the google groups post below for good code.
http://groups.google.com.au/group/formtastic/browse_thread/thread/dea717f058084ad5
Can't re-produce it still as mentioned in google group. You could always clone my "test_app" and to prove it that way, or try with a spec.
ruckus-matte
Thu Oct 22 11:09:01 -0700 2009
| link
I'll do that this weekend. Letcha know what I find out. Thanx. BTW - I don't know if this affects it but I'm using the 0.9.0 gem from gemcutter, not github.
ehutzelman
Thu Oct 22 21:10:05 -0700 2009
| link
I noticed the same issue (using the gemcutter 0.9.0 version as well). I just reinstalled formtastic from github (0.2.4) and it fixes the issue. Looks like you just need to update the gem in gemcutter?
justinfrench
Thu Oct 22 22:28:45 -0700 2009
| link
The gemcutter one is the newest gem. Looks like I need to do a diff between the two tags and see what's busted. I have a hunch ;)
Same issue here with the 0.9.0 from gemcutter.
Regards, René
As mentioned, I believe the only way to address this is a spec or a real life scenario test-app.
justinfrench
Fri Oct 23 15:44:11 -0700 2009
| link
Is this occurring in nested forms, or just in regular forms? Will help me create a failing spec.
Regular form in my case. Here is my example:
I have a user model:
id :integer(4) not null, primary key
active :boolean(1) not null
login :string(255) not null
...Here is the erb
<% semantic_form_for @user, :url => user_path do |f| %> <% f.inputs :name => 'Login Daten' do %> <%= f.input :active, :label => 'Aktiv?' %> <%= f.input :login, :label => 'Login' %> <%= f.input :password, :label => 'Passwort' %> <%= f.input :password_confirmation, :label => 'Passwort wiederholen' %> <% end %> <% f.inputs :name => 'Persönliche Daten' do %> <%= f.input :firstname, :label => 'Vorname' %> <%= f.input :lastname, :label => 'Nachname' %> <%= f.input :email, :label => 'E-Mail' %> <% end %> <% f.buttons do %> <%= f.commit_button 'Konto einrichten' %> <% end %> <% end %>The resulting html:
<li class="boolean required active" id="user_active_input"> <label for="user_active" label="Aktiv?"> <input name="user[active]" type="hidden" value="0"> <input checked="checked" id="user_active" name="user[active]" type="checkbox" value="1"> <label for="user_active">Aktiv?<abbr title="required">*</abbr></label> <abbr title="required">*</abbr> </label> </li>
justinfrench
Sat Oct 24 14:47:07 -0700 2009
| link
Ok, I'll take this. I'll write some more specs, see if I can find it. Expect a fix by the end of the month, preferably much sooner!
justinfrench
Sat Oct 24 15:07:25 -0700 2009
| link
Ok, this is easy. The bug was introduced in d8290cf4 by grimen (sorry to point fingers!)... this line has two calls to label():
self.label(method, input << self.label(method, options_for_label(options)), options_for_label(options))Looking into a fix now
justinfrench
Sat Oct 24 16:08:42 -0700 2009
| link
Resolved in 5549c6a, grimen, please check my work, close this issue, and we'll issue a new gem
-
Fails with certain validation options, such as:
validates_presence_of :title, :custom => "Raurrr!"
...when neither :if or :unless is specified. This should be handled without assuming either :if or :unless, now it assumes it's either :if or :unless - even if there's none of em.
Comments
justinfrench
Wed Oct 21 15:38:27 -0700 2009
| link
pulled in, closing.
-
Line 2 in init.rb since JustinFrench-namespace got removed. Sent a pull request.
Comments
justinfrench
Wed Oct 21 15:38:10 -0700 2009
| link
pulled in, closing.
-
Error: undefined method `select_html' for date field
3 comments Created 2 months ago by zufTo reproduce bug. In migration create date field:
create_table :articles do |t|
t.date :publication_dateend
And then use simple form like this:
-semantic_form_for article do |form| =form.inputs =form.buttons
Comments
justinfrench
Wed Oct 21 02:24:47 -0700 2009
| link
What Rails version? What Formtastic version? Can I see the stacktrace?
Sorry. We parsed our log in details and found that it was because of conflicts with rutils (gem for additional Russian language support in rails).
Anyway detailed info for users with same problems:Rails 2.3.4
formtastic (0.9.0) - installed few hours before bug submit as gem/home/egor/projects/mycms/vendor/plugins/rutils/lib/integration/rails_date_helper_override.rb:95:in
select_month' /usr/lib/ruby/gems/1.8/gems/formtastic-0.9.0/lib/formtastic.rb:797:insend' /usr/lib/ruby/gems/1.8/gems/formtastic-0.9.0/lib/formtastic.rb:797:indate_or_datetime_input' /usr/lib/ruby/gems/1.8/gems/formtastic-0.9.0/lib/formtastic.rb:783:ineach' /usr/lib/ruby/gems/1.8/gems/formtastic-0.9.0/lib/formtastic.rb:783:indate_or_datetime_input' /usr/lib/ruby/gems/1.8/gems/formtastic-0.9.0/lib/formtastic.rb:711:indate_input' /usr/lib/ruby/gems/1.8/gems/formtastic-0.9.0/lib/formtastic.rb:949:insend' /usr/lib/ruby/gems/1.8/gems/formtastic-0.9.0/lib/formtastic.rb:949:ininline_input_for' /usr/lib/ruby/gems/1.8/gems/formtastic-0.9.0/lib/formtastic.rb:109:insend' /usr/lib/ruby/gems/1.8/gems/formtastic-0.9.0/lib/formtastic.rb:109:ininput' /usr/lib/ruby/gems/1.8/gems/formtastic-0.9.0/lib/formtastic.rb:108:inmap' /usr/lib/ruby/gems/1.8/gems/formtastic-0.9.0/lib/formtastic.rb:108:ininput' /usr/lib/ruby/gems/1.8/gems/formtastic-0.9.0/lib/formtastic.rb:257:ininputs' /usr/lib/ruby/gems/1.8/gems/formtastic-0.9.0/lib/formtastic.rb:257:inmap' /usr/lib/ruby/gems/1.8/gems/formtastic-0.9.0/lib/formtastic.rb:257:ininputs' /home/egor/projects/mycms/app/views/articles/_form.haml:3:inrun_haml_app47views47articles47_form46haml_locals_article_form_object' /home/egor/projects/mycms/app/views/articles/form.haml:1:in_run_haml_app47views47articles47_form46haml_locals_article_form_object' /home/egor/projects/mycms/app/helpers/articles_helper.rb:4:inarticle_form' /home/egor/projects/mycms/app/views/articles/edit.haml:2:in `_run_haml_app47views47articles47edit46haml'And thank you very much for your highly efficient plugin!
justinfrench
Wed Oct 21 04:24:47 -0700 2009
| link
My pleasure! Closing this issue.
-
Provide a warning when trying to run old formtastic_stylesheets generator
1 comment Created 2 months ago by justinfrench -
Comments
-
Updated README to reflect new gemcutter gem and install instructions
0 comments Created 2 months ago by justinfrenchComments
-
input.hobbies, :as => :check_boxes, :collection => Hobby.all.in_groups(4)
OR
input.hobbies, :as => :check_boxes, :columns => 4
Comments
justinfrench
Tue Oct 20 15:34:51 -0700 2009
| link
Are you talking about purely a display issue? It sounds like you're asking for the DSL to let you describe that if there were 11 hobbies, display the checkboxes 4-per-row, with the final line containing 3 (4 + 4 + 3 = 11).
If this is correct, I'd argue that this is purely a presentational issue. Formtastic renders the correct markup for a list of N (eg 11) checkboxes, and the it's the job of the stylesheet author to choose how to display that markup.
To achieve your 4-per-line goal, I think each li would need to have a fixed width of 25% of the ol wrapper, and float them to the left.
If this isn't what you're after, or if you'd like help working out the CSS, perhaps jump on the google group, paste in some screen shots, and we'll help sort it out.
I'll close this issue for now.
-
Getting this error "Missing FormtasticGenerator class in <path_to_generator_file>". Checking the file, the class is FormtasticConfigGenerator with a file named formtastic_generator.rb... If I change the class to FormtasticGenerator it works as it should... This was the gem hosted on gemcutter.org.
Looks like it is correct here on git...
Comments
This I patched already, I'm sure. Maybe not got into the latest gem though.
justinfrench
Mon Oct 19 14:15:00 -0700 2009
| link
Duplicate bug, will be in next gem (couple of days tops).
-
Hi,
This thread: http://groups.google.com.au/group/formtastic/browse_thread/thread/9bb5d808d2a9adbf talk about cancel button.
I write a method that I'm using into a initializer file (is a monkey patch in really) but do the proposed feature.
I know that's obstrutive solution using
window.history.back()orwindow.location = url;but the unobstrutive solution aren't greater IMHO (create a inline form reseting all css properties of this form elements using action to proposed url and get method).This sounds to a bad workaround.
The dev will be advised about obstrutivity and I guess that's not a problem considering dev can make the unobstrutive solution by yourself if really needed.
You will use the cancel_button method:
- form.inputs do = form.submit_button = form.cancel_button = form.cancel_button admin_pages_path = form.cancel_button admin_pages_path, { :button_html => { :class => 'pretty_button' } } = form.cancel_button admin_pages_path, 'Cancel updates' = form.cancel_button admin_pages_path, 'Cancel updates', { :button_html => { :class => 'pretty_button' } }The default url is :back, this means, window.history.back() and the default button text is I18n.t('formtastic.cancel', :default => 'Cancel').
If you specify a url, this will be "window.location = #{url.to_json}"
I guess this solve 99.9% of cancel button cases.
See the code: http://paste.pocoo.org/show/145765/
Comments
DiMarcello
Fri Oct 23 23:43:21 -0700 2009
| link
you could also do like I always do
create a button with this html, that is unobtrusive
<a href="/back"><button type="button">Back</button></a>in (formtastic)rails that would be
def back_button(*args) options = args.extract_options! options[:href] ||= :back value = args.first || back_button_text #same as save_or_create_button_text but with a 'back' as prefix button_html = options.delete(:button_html) || {} button_html[:type] ||= "button" template.content_tag(:li, template.link_to(template.content_tag(:button, value, button_html), options.delete(:href)), :class => "back") end+1, event though this been up for discussion before. The buttons needs to be revised no matter what, should follow the inputs way also. I would actually like this or similar in 1.0 as a temporary solution.
@DiMarcello
Your solution doesn't work into IE6, I guess. I remember that code doesn't work into some IE version.
Can you try?
justinfrench
Wed Dec 02 01:51:22 -0800 2009
| link
I have a similar implementation of this under development as part of "pretty buttons", so I'm closing this issue as the "pretty buttons" issue will suffice.
-
Method name could be added to the enclosing li as a class
2 comments Created 2 months ago by elandesignNot sure if this belongs here or on the Google group? More of a feature request than an issue.
This change would allow styles to be applied universally to the fields specifically named attributes.
e.g. assuming you have multiple models with a name (or a telephone or postal/zip code...) attribute, and want all name fields to have the same width
<% semantic_form_for @task do |form| %> <%= form.inputs :name %> <% end %>would render as (simplified)
<form class="formtastic task ... > <fieldset class="inputs"> <ol> <li class="string required name" id="task_name_input"> <label for="task_name">Name<abbr title="required">*</abbr></label> <input type="string" ... /> </li> </ol> </fieldset> </form>allowing
.formtastic .name input { width: 80%; }with overrides for specific models
.formtastic.person .name input { width: 100%; }instead of having to repeat for every model with the name attribute
#task_name, #model2_name, #model3_name, #model4_name, ... #modelx_name { width: 80%; } #person_name { width: 100%; }It should be a one line change. I'll fork and make the change if you think it's a feature worth adding.
Paul.
Comments
elandesign
Sat Oct 17 10:20:23 -0700 2009
| link
Scratch that - sent a pull request...
justinfrench
Sun Oct 18 13:26:09 -0700 2009
| link
commit here:
http://github.com/elandesign/formtastic/commit/0958ac3f19584e4fabe180aac5a47ae9869f1f2dwill pull in now
-
HI,
Installed 0.2.5 from gemcutter.org.
Running script/generate formtastic fails:
$ script/generate formtastic Missing FormtasticGenerator class in d:/binx/ruby/lib/ruby/gems/1.8/gems/formtastic-0.2.5/generators/formtastic/formtastic_generator
.rbscript/generate formtastic_stylesheets is working however.
Did something get missed in the 0.2.5 build?
Comments
justinfrench
Fri Oct 16 04:59:19 -0700 2009
| link
Just sloppy coding by me :)
Have fixed, will be in the next gem, thanks for the tip!
-
8 comments Created 2 months ago by robertwahlerPull request: default accesskey for commit_buttonfor 1.xxThis commit provides a quick way to setup a default submit button accesskey for all your forms that use the commit_button method.
http://github.com/robertwahler/formtastic/commit/2478900b2e200f39c6e492f174d6cc3512ba5479
Comments
justinfrench
Fri Oct 16 05:03:09 -0700 2009
| link
awesome, will pull in
justinfrench
Sun Oct 18 13:33:31 -0700 2009
| link
Actually, doesn't apply cleanly due to some of your prior commits I guess. Will have a look when I have time.
This will def not apply cleanly since my I18n-commit - that method is sort of rewritten. We'll have to apply this manually. I'll do it now as this is a good usability/accessibility feature.
robertwahler
Sun Oct 25 07:25:27 -0700 2009
| link
I'll be happy to help. Would it be helpful if I provided the changes in patch format against the current master? I can do that on Monday and please let me know if there is a more efficient way that I could contribute.
justinfrench
Sun Oct 25 14:52:54 -0700 2009
| link
The forking and the forkqueue is great, but there's an obvious downside in that we're moving pretty fast at the moment and you can obviously end up with a patch that can't be applied. I'm not sure if there's a better way, but for me, this usually involves a new local branch and some juggling of commits to get my master up-to-date with the main repo, then re-applying my commits cleanly.
robertwahler
Mon Oct 26 10:09:43 -0700 2009
| link
Thanks for the pointers. I applied just the commit_button changes onto the current master in a branch of my fork.
http://github.com/robertwahler/formtastic/tree/commit_button_accesskey
The commit is here:http://github.com/robertwahler/formtastic/commit/7a3be5be57d9c0f34e78362af23c1b108ef0ff9a
Hope this helps.
justinfrench
Mon Oct 26 13:46:28 -0700 2009
| link
Awesome, pulled in, thanks!
-
I had to manually specify the label for a check box while the other fields correctly found their translations:
<%= form.input :terms, :as => :boolean, :label => I18n.t('formtastic.labels.competition.terms') %>Comments
Ouch, for some reason boolean fields defined it's own label, fixed:
http://github.com/grimen/formtastic/commit/3cbc4374c22532ef04cf012b1e7b2008896a22fc
Justin, pull? ;)
justinfrench
Tue Oct 13 03:32:51 -0700 2009
| link
Pulled, closing. Thanks Grimen!
-
"Missing Dependencies Looks like we may be missing some dependencies on this build box - we have been notified of this automatically. Here are the ones we caught:
test-unit"They don't want top add the gem when everything should work "out of the box", so I need to know why we're requiring it (from memory, it was 1.9 compat), and figure oput a solution.
Comments
Not completely sure what you mean. test-unit is not really required I noticed, but still can't cause any big issues as Rails requires it - never came across any system without test-unit. Should be removed though. Maybe it was me adding it without reflecting.
justinfrench
Mon Oct 12 14:28:31 -0700 2009
| link
test_helper has the following, added by you:
# To get the specs to run on Ruby 1.9.x. gem 'test-unit', '= 1.2.3' gem 'activesupport', '>= 2.3.3' gem 'actionpack', '>= 2.3.3' gem 'rspec', '>= 1.2.6' gem 'rspec-rails', '>= 1.2.6' gem 'rspec_hpricot_matchers', '>= 1.0.0' gem 'hpricot', '>= 0.6.1'
Can you please comment out each and review if they're actually required for 1.9? I just switched to Snowy Leopard and don't have 1.9 running yet.
Yep, actually started with this already, and added smarter spec dependency loading, i.e. try to use libraries already loaded by the Rails host app:
http://github.com/grimen/formtastic/commit/7f3e1af630f343e478ec56c9284a89045bf5d5df
There was a encoding issue also, fixed in the commit before that one.
Btw, using both ruby_switcher and rvm (install it, very straightforward and good!) Ruby 1.9.x installations, you need to specify gem and version to get things to rock. Ruby 1.9 is more whiny, but probably for good cause. =)
justinfrench
Mon Oct 12 15:25:45 -0700 2009
| link
Awesome, thanks! Pulled in, runcoderun is green, closing ticket.
-
4 comments Created 2 months ago by javiermAllow custom "name" and "value" attributes for has_many relationshipsnot surexI'm using the plugin Acts as Taggable On, and I'm trying to generate a list of checkboxes with the available tags. So the following code:
f.input :tags, :as => :check_boxesGenerates the following HTML for each checkbox:
<label for="post_tag_ids_15"><input type="hidden" value="" name="post[tag_ids][]"/><input type="checkbox" value="15" name="post[tag_ids][]" id="post_tag_ids_15"/> css</label>But, since I'm using Acts as Taggable On, I'd like to do something like this:
f.input :tags, :as => :check_boxes, :input_name => 'tag_list', :value_method => :nameAnd it would generate the following HTML:
<label for="post_tag_ids_15"><input type="hidden" value="" name="post[tag_ids][]"/><input type="checkbox" value="css" name="post[tag_list][]" id="post_tag_ids_15"/> css</label>In other words, I'd like something similar to the options the check_box_tag method offers.
P.S: By the way, a good form builder was the #1 thing I used to miss in Rails, so thanks!
Comments
There's a typo in the last piece of HTML:
<label for="post_tag_ids_15"><input type="hidden" value="" name="post[tag_list][]"/><input type="checkbox" value="css" name="post[tag_list][]" id="post_tag_ids_15"/> css</label>
justinfrench
Sun Oct 11 15:13:29 -0700 2009
| link
Ok, so there seems to be two things you're looking for here:
1) the ability to give the input a different name (like tag_list)
This is such an edge case that I'm not super excited about supporting it. Have you tried doing an f.input :tag_list, :as => :check_boxes, :collection => @post.tags ?
Or, have you tried assigning @post.tag_list = @post.tag_ids in the controller?
Or have you tried implementing the conversion as a before_validation hook on the model?
I'd suggest any of these are better than fiddling with this stuff in the view, but that's just me :)
2) the ability to specify something other than the ID for the value of a checkbox
Try the :value_method option, which allows you to specify which method to call on each object in the collection for use as the value attribute of the check box (so you might want :name or :label or :to_s or whatever attribute in your model has the "css" string.
f.input :tags, :as => :check_boxes, :value_method => :name
Let me know how you go with that... if it doesn't work, it's a bug. If it does work, I think we're missing some documentation :)
Well, well, thank you so much!
About the :value_method option... it's funny I suggested to add it to the current API, and it was already there. I was pretty sure I had actualy tried it before I reported the issue, but obviously I was mistaken.
Everything worked with:
f.input :tag_list, :as => :check_boxes, :collection => Tag.all, :value_method => :nameSo you can either close this issue or mark it as a documentation one.
Thanks!
justinfrench
Mon Oct 12 13:18:40 -0700 2009
| link
Documentation added in http://github.com/justinfrench/formtastic/commit/ed49dade3af52cd7f0e54ad5b6604c11c8a8a7cb (although those private methods still aren't in the Rdoc, but that's a separate issue ;))
-
Nice piece of code you guys have here.
I added the ability to use a proc on the label option. I wanted to wrap some extra html around my label. I'm no Ruby expert so you might want to take a look, maybe this isn't the best way to go about it and I've tested nothing. =)
http://github.com/theworkerant/formtastic/commit/b5a3a6f982d457b1e59be06a25ef035576bf1ec3
Comments
justinfrench
Wed Oct 07 19:40:12 -0700 2009
| link
Fantastic! xaviershay has a similar patch in his fork if you want to take a look. There's even an issue in the tracker already (issue #10), so I'll close this one, but if we can get some spec coverage and documentation, I'm totally in favour of this feature.
-
Will probably do this for 1.0 and migrate people away from the Github version.
Update: next gem will be there in a few days
Comments
Yea, I noticed Formtastic was not on there. Makes sense!
Would be great! But why wait until 1.0? It's a matter of typing
gem push yourgem-0.0.1.gem
justinfrench
Sun Oct 11 02:37:21 -0700 2009
| link
Yes, well, now that I've learned that Github gems aren't coming back, this will obviously be done for the next gem we push (0.2.5 or 0.9 I guess)
I would suggest to do it asap, it took me 30 seconds to do it the first time. =)
ASAP would be really awesome. I'd really like to have access to the nested_attributes + HAML fix... Thanks!
justinfrench
Wed Oct 14 20:43:51 -0700 2009
| link
you can install as a plugin ;)
next gem will be there in a few days, depending on how some review/testing goes
justinfrench
Thu Oct 15 15:32:23 -0700 2009
| link
meantime:~ $ sudo gem install formtastic
Successfully installed formtastic-0.2.5
1 gem installed
Installing ri documentation for formtastic-0.2.5...
Installing RDoc documentation for formtastic-0.2.5...
meantime:~$closing issue
-
Could you please update your gem for release to Gemcutter (or even RubyForge)?
Comments
justinfrench
Wed Oct 07 14:41:41 -0700 2009
| link
What's the hurry? There's the GitHub-hosted justinfrench-formtastic gem, which is prefect for this pre 1.0 phase. Anyway, I'll close this ticket and create a new one for getting the canonical gem onto Gemcutter :)
laserlemon
Wed Oct 07 14:45:44 -0700 2009
| link
Thanks for the quick reply! I'm trying to get a hosting environment set up with Engine Yard and your gem plays a big part. Unfortunately, Github gems are down. They say:
"Gem Building is currently disabled. Please see gemcutter.org in the meantime. There is no ETA on the return of gem building."
…but there's no way (is there?) to build any subsequent version of the gem on GitHub (check out the nice message at http://gems.github.com/ ).
justinfrench
Wed Oct 07 14:56:03 -0700 2009
| link
That's gem building. I can still install the Gem -- I just tried it on my own machine, updating to 0.2.4, works fine!
justinfrench
Wed Oct 07 15:00:22 -0700 2009
| link
Right. I thought it was just automatic gem building that was disabled. In that case, I guess the next gem (probably the 0.9.0 release candidate) will be on gemcutter, unless GitHub gets sorts their stuff out :)
laserlemon
Wed Oct 07 15:03:28 -0700 2009
| link
Great, thanks!
-
Hi
If your app is localized, passing :as => :date to an input chokes, saying: 'can't convert Array into String' (line 766). I'm not exactly sure why, and having a :date.order in your i18n-file doesn't help. All you can do is make sure you pass an :order array to the input.
Like I said, not sure what exacly goes wrong, just wanted to report it. I'm going to look into it when I have more time.
Best,
TomasComments
Actually, a broken i18n-file was the culprit. Sorry for the confusion.
I'd still say that it's not the optimal behavior though:
inputs = options.delete(:order) || I18n.translate(:'date.order') || [:year, :month, :day]The expression in the middle doesn't return nil if the translation wasn't found, it returns a String instead, which code that follows chokes on, expecting it to be an Array.
justinfrench
Tue Oct 06 16:30:47 -0700 2009
| link
thanks... tagged it for 0.9, if you get a chance, a patch would be great, otherwise, one of us will pick it up
justinfrench
Wed Oct 07 02:16:24 -0700 2009
| link
Thanks, pulled in. Had to tweak the specs to pass for me.
-
I've set up a one-to-one polymorphic association between two models, Parent and Child.
models/parent.rb:class Parent < ActiveRecord::Base belongs_to :resource, :polymorphic => true, :dependent => :destroy, :autosave => true endmodels/child.rb:class Child < ActiveRecord::Base has_one :parent, :as => :resource, :dependent => :destroy, :autosave => true accepts_nested_attributes_for :parent, :allow_destroy => true attr_accessible :parent_attributes endWorks fine.
Using Rails' built-in
form_for(@child)helper in my views yields the expected results: the controller actions receive theparamshash in the right format, i.e.params[:child][:parent_attributes].However, using
semantic_form_for(@child)andform.inputs :for => @child.parent {|t|…}will only returnparams[:child][:parent], notparams[:child][:parent_attributes].Do you know what I mean?
I'm currently using HAML, but ERB seems to yield the same results. Formtastic's at 0.2.4.
Comments
justinfrench
Tue Oct 06 16:24:22 -0700 2009
| link
Grimen? José?
Don't know about this specific case, but I haven't got semantic_form_for or form.inputs :for => to work at all (don't use ERB, so cannot tell if it's HAML - but I believe José meant that). That's why there's still a ticket for 0.9 - if it's the same issue, no clue. I use form_for in these cases, but it really needs to be adressed. xP
Check the
paramsin your log, I bet you'll see the hash structure is wrong.carlo, are you able to even render the fields? I can't because of the HAML/Formtastic bug. I put up a example project here of where Formtastic fails with HAML:
justinfrench
Sun Oct 11 15:14:16 -0700 2009
| link
Or where HAML fails with Formtastic ;)
Yes, HAML is stepping Formtastic on the toes in this dance. =)
justinfrench
Mon Oct 12 13:09:22 -0700 2009
| link
I've reviewed this ticket, I think it has nothing to do with HAML... I think it's suggesting that we're supplying nested attributes in a way that isn't expected by Rails (or at the very least, by Carlo!).
I'll research this a bit more. We have to do it The Rails Way, and we have to get it right before 1.0.
Oh, didn't see that carlos mentioned ERB was also faulty, ooops. Otherwise it made very much sense, because params was also messed up with the HAML issue for natural reasons.
Status: Messaged carlos, and awaiting reply.
We won't get any feedback from Carlo on this in quite a while it seems as he told me he's too busy, so we need to re-produce this one to get anywhere. I'm not completely sure what the issue is - and if it is an issue - from this ticket.
justinfrench
Sun Oct 18 19:55:05 -0700 2009
| link
It seems pretty clear to me from the Rails docs that nested attributes in Rails forms should be following the pattern params[:child][:parent_attributes] rather than the current params[:child][:parent].
http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html
The same seems to be true in Rails3/edge at the moment.
Making this change will represent some challenges for people upgrading from the 0.2.x series of gems, but I think we have to pull in line with Rails before Formtastic 1.0.
I've created a new branch for us to explore this, along with a failing spec of what I believe is the correct desired behaviour:
http://github.com/justinfrench/formtastic/tree/nested_attributes
http://github.com/justinfrench/formtastic/commit/21c104025a96c9cb9226b496f50a2c8352f929d5This example is for a parent => child relationship (rather than child => parent), but I don't believe it matters, the Rails docs illustrate a parent => child relationship with the _attributes suffix in the params key.
Now I'll go look for the fix :)
justinfrench
Sun Oct 18 20:01:10 -0700 2009
| link
Also see the fields_for docs:
http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#M001605
justinfrench
Sun Oct 18 22:21:22 -0700 2009
| link
Ok, now I'm even more confused, because Grimen's sample app with a nested form works perfectly :/
Code: http://github.com/grimen/test_app
Params hash when submitting the form: http://gist.github.com/213112
Puzzled.
Two puzzled developers: Could either be a good sign, or a bad sign. xD Nah, on the real...Rails core fields_for is the returning call in all of the code, so I can't see how it can fail by the look of it.
justinfrench
Mon Oct 19 14:25:45 -0700 2009
| link
I don't understand what's happening in the spec I wrote then.
http://github.com/justinfrench/formtastic/commit/21c104025a96c9cb9226b496f50a2c8352f929d5Hi guys,
many thanks for diving into this issue, I really appreciate it. I'm currently up to my eyeballs in work (working on-site for a client all day long), so I'm pretty much out of spare time at the moment — i.e. my silence doesn't mean I've lost interest, far from it! :)
I'll try to get back to you with some test results and more info as soon as I can, promised. Please don't stress yourself out over this.
Talk to you soon,
CarloPS: BTW, Justin's right, that's exactly what I meant:
It seems pretty clear to me from the Rails docs that nested attributes in Rails forms should be following the pattern params[:child][:parent_attributes] rather than the current params[:child][:parent].
Addendum: maybe it has something to do with my views? I set up a
semantic_form_for(@child) do |form|in, say,new.haml, and then handformover to a partial. See this gist: http://gist.github.com/213751The thing is: it works in the forms, the related parent model attributes are displayed correctly. But maybe I'm doing it wrong?
Seems OK, except for this line:
- t.input :some_text
HAML-issue is fixed, so you can use "=" again. Anyway, that should not affect this issue I believe.
@Justin: Will look at the spec out put tomorrow when I get time.
justinfrench
Tue Oct 20 15:23:20 -0700 2009
| link
Ok, I've got this one sorted out, I think :)
See this gist: http://gist.github.com/214637
The first thing you need to trigger the attributes suffix on the params is for the parent model responds to {association}attributes= (which you get when you call accepts_nested_attributes_for()), and it needs to be able to reflect on the association. That's all built-in stuff that fields_for needs, and we're just leaning on the same code really.
Given you've probably already crossed that hurdle, here's how Rails' built-in fields_for works:
- if you provide a symbol for the association name (fields_for(:author)), you get post[author_attributes]
- if you provide an associated object (like you are, eg fields_for(@post.author) you get post[author]
And for Formtastic, it's a similar world, but we seem to have provided a third option:
- inputs :for => :author gives you post[author_attributes]
- inputs :for => @new_post.author gives you post[author]
- inputs :for => [:author, @new_post.author] gives you post[author_attributes]
So, I can't really decide how I feel about all this behaviour long-term (I'm not sure I like the way Rails fields_for works), but that's how everything fits together right now.
In short, I think you need to change inputs :for => @child.parent to an array which has the association name and the associated object.
I've committed some new specs to describe this behaviour (http://github.com/justinfrench/formtastic/commit/c1a3581d77695da39d03cdd46a3a82455da10e60), which should help us if we decide something should change.
Going to close this issue for now, please re-open if needed.
-
feature: automatically add :html => {:multipart => true} if form contains a file field
2 comments Created 2 months ago by bitzestye.g. when a model uses paperclip it would be awesome if the form could detect this and add in the multipart
Comments
freelancing-god
Mon Oct 05 11:56:09 -0700 2009
| link
This has been discussed on the google group - unfortunately, the form tag has already been rendered by the time the file field is requested. The only way to do this would be some severe hacking, possibly of Rails internals.
http://groups.google.com/group/formtastic/browse_thread/thread/4199494086f593da
Still, it would be a great feature.
justinfrench
Mon Oct 05 13:14:03 -0700 2009
| link
Yes, sadly, there's no real way forward with this right now, closing.
-
4 comments Created 2 months ago by grimencommit button should have class reflecting its actionfor 1.0xExample:
form action="/posts" class="validate formtastic post" id="new_post" method="post" ... input class="create" id="post_submit" name="commit" type="submit" value="Create" ...
(Note: GitHub markdown hating on my HTML-tags...)
Reasons:
- Easier to style buttons based on "what it does" in a more logical way. The already defined attributes ID, NAME, etc are usually not atomic enough.
- More semantic for developers used to REST
- No cost/drawbacks - it's just a class, and it's trivial to implement
The buttons is of course - as already discussed - on the wall for 1.x, so just putting this up as a reminder of something that it should support later on.
Comments
justinfrench
Mon Oct 05 13:22:35 -0700 2009
| link
Fine with me. Even for 0.9.
justinfrench
Wed Oct 07 14:44:33 -0700 2009
| link
Removed "suggestion" from the title, this is a good idea!
When I was touching commit_button anyway...
http://github.com/grimen/formtastic/commit/2d5528797a81c1f93dbc85cca1271e71eea0226d
justinfrench
Sat Oct 24 14:42:48 -0700 2009
| link
Pulled, closed.
-
5 comments Created 2 months ago by bitzestyspecifing default on datetime/date doesn't workfor 1.xxI can't seem to specify that the default date for the select should be today, with DateTime.now, or Date.today.
<%= form.input :start_date, :as => :date, :start_year => Time.now.year, :end_year => Time.now.year + 10, :default => Date.today %>Comments
justinfrench
Sat Oct 03 15:16:32 -0700 2009
| link
There's no such option as :default on any of the inputs. Providing default values in the views is not supported by Formtastic at this time. My preferred method for setting defaults is either at the controller level or the model level.
Ah ok, for a second I thought I was going crazy that the Rails API changed.
Thanks
justinfrench
Mon Oct 05 13:21:46 -0700 2009
| link
Is there a :default option in standard Rails form helpers that I've missed?
on date_select (ActionView::Helpers::DateHelper)
:default - Set a default date if the affected date isn‘t set or is nil.
justinfrench
Tue Oct 06 16:25:37 -0700 2009
| link
ok, i think it's really odd that only some form helpers in rails have the defaults, but we should take a look into this after 0.9/1.0
-
Comments
justinfrench
Sat Oct 03 05:15:26 -0700 2009
| link
Yep.
Example: Using the gem, the tasks are not visible - and not really easy to require in Rakefile right now. I got a solution (that I used before for my fork of "bootstrapper") on this, but it seems it's not very trivial to require Rake-tasks from gem without altering the project Rakefile.
Note: You mean? http://github.com/justinfrench/formtastic/commit/852751b366070b0235823f20695b919e9cb71577
justinfrench
Thu Oct 08 13:31:57 -0700 2009
| link
I was pretty undecided on the whole generators vs rake tasks debate, but now that I know rake tasks in gems aren't loaded into the parent app, I'm utterly convinced we should keep using generators for now.
We'll see what happens with Rails 3 and a few other ideas I have kicking around (hint see my new plugin "publicious" that I'm experimenting with).
So I'll be nuking the rake task, bringing the stylesheet generator back and tidying up the gemspec.
yep, but add default initializer generator as well - it's quite annoying to create one manually. I my project "validatious-on-rails" I have: "./script/generate validatious" which purpose is to generate everything to get started fast and easy. So, It would make sense to have "./script/generate formtastic" that geenrates stylesheets and initializer. With an option "./script/generate formtastic --sass" we could generate a sass-stylesheet instead, etc. Btw, don't nuke the form-generator, it's very neat! =)
justinfrench
Sun Oct 11 02:36:17 -0700 2009
| link
Done and done, closing.
-
15 comments Created 3 months ago by activestyluscheckbox inputs should not be nested inside their labelsnot surexIn my humble experience, this is just asking for trouble. It's the cheap w






You can already do this with the Formtastic I18n API, which is the future way of specifying string values for Formtastic forms.
en: formtastic: actions: create: "Add Candidate" update: "Save Candidate" my_custom_label: "Yep!"Explicit labels in views might even disappear in Formtastic 2.0.
Hello grimen,
I have a question then. How do you specify different create and update labels for different forms?
I also have an opinion in case you care. I understand why it's good to be able to specify strings in YAML, but forcing to do it, for me, would not be very agile. I like how Ruby on Rails is very agile and how you can do things quick and dirty or nice and good. I would like to formatistic to still offer that possibility.
If you check the README example:
en: formtastic: actions: create: "Create..." article: create: "Add..." post: create: "Add Candidate" update: "Save Candidate" my_custom_label: "Yep!"etc.
Solves 95%-ish of cases I would say in a DRY and very flexible/maintainable way. I think the consensus among core maintainers at least is that more complex cases than this only makes the DSL bloated, and even harder to maintain and spec. I would also say that more flexibility leads to more confusion. If more cases needs to be handled, this can be handled in these very cases with a few helpers to extend Formtastic with such behavior - that's very straightforward with Ruby meta-programming, which makes it less of a pain. Maybe you should bring this discussion to the groups so that others can join in?