Every repository with this icon (
Every repository with this icon (
| Description: | A Rails form builder plugin with semantically rich and accessible markup. It's deliciously close to 1.0! edit |
-
2 comments Created 5 months ago by justinfrenchdocx*_input methods need to be added to rdoc for documentationfor 1.0xthey're private methods right now, so they need to be forced into the documentation I guess
Comments
-
0 comments Created about 1 month ago by justinfrenchdocxdocumentation for date/time selectsfor 1.0xnone of the options are documented (eg :include_blank)
Comments
-
2 comments Created about 1 month ago by grimen@grimenxdocxRDoc for I18n for the affected methodsfor 1.0xMost only documented in README right now.
Comments
justinfrench
Sat Oct 24 16:10:50 -0700 2009
| link
I think this is part of the greater issue with the documentation (all the docs for each input are on the private methods). Changing the tag to 1.0, we'll address it all at once (soon).
-
0 comments Created about 22 hours ago by grimen@grimenxfor 1.0xLocalized titles don't work for the nested forms casei18nx...it seems forgot this single case: inputs_for_nested_attributes
Comments
-
2 comments Created 7 days ago by justinfrenchDate/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
-
Hi,
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, 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.
-
11 comments Created about 1 month ago by ivanvanderbylInvalid Markup created from nested inputs, missing <li>..</li>for 1.0xThe following form creates invalid markup by omitting the li tags after ol when creating new fieldsets.
<% semantic_form_for(@application) do |f| %> <%= f.inputs :financed_amount, :finance_term %> <% f.inputs :for => :applicants do |af| %> <% af.inputs :for => :personal_details do |pdf| %> <%= pdf.inputs :first_name, :middle_name, :last_name, :class => "inline-group" %> <%= pdf.inputs :date_of_birth %> <% end -%> <% end -%> <%= f.buttons :commit %> <% end -%> <form action="/applications/3" class="formtastic application" id="edit_application_3" method="post"> <div style="margin:0;padding:0;display:inline"> <input name="_method" type="hidden" value="put"/> <input name="authenticity_token" type="hidden" value="7R4cdFo7OnloRFVe8lyocG7an/bn5ooOuGL+f2wwTh4="/> </div> <fieldset class="inputs"> <ol> <li class="numeric required financed_amount" id="application_financed_amount_input"> <label for="application_financed_amount">Financed amount<abbr title="required">*</abbr></label> <input id="application_financed_amount" name="application[financed_amount]" size="50" type="text" value="25000.00"/> </li> <li class="numeric required finance_term" id="application_finance_term_input"> <label for="application_finance_term">Finance term<abbr title="required">*</abbr></label> <input id="application_finance_term" name="application[finance_term]" size="50" type="text" value="24"/> </li> </ol> </fieldset> <input id="application_applicants_attributes_0_id" name="application[applicants_attributes][0][id]" type="hidden" value="2"/> <fieldset class="inputs"> <ol> <fieldset class="inputs"> <ol> <fieldset class="inline-group"> <ol> <li class="string required first_name" id="application_applicants_attributes_0_personal_details_attributes_first_name_input"> <label for="application_applicants_attributes_0_personal_details_attributes_first_name">First name<abbr title="required">*</abbr></label> <input id="application_applicants_attributes_0_personal_details_attributes_first_name" maxlength="255" name="application[applicants_attributes][0][personal_details_attributes][first_name]" size="50" type="text" value=""/> </li> <li class="string required middle_name" id="application_applicants_attributes_0_personal_details_attributes_middle_name_input"> <label for="application_applicants_attributes_0_personal_details_attributes_middle_name">Middle name<abbr title="required">*</abbr></label> <input id="application_applicants_attributes_0_personal_details_attributes_middle_name" maxlength="255" name="application[applicants_attributes][0][personal_details_attributes][middle_name]" size="50" type="text" value=""/> </li> <li class="string required last_name" id="application_applicants_attributes_0_personal_details_attributes_last_name_input"> <label for="application_applicants_attributes_0_personal_details_attributes_last_name">Last name<abbr title="required">*</abbr></label> <input id="application_applicants_attributes_0_personal_details_attributes_last_name" maxlength="255" name="application[applicants_attributes][0][personal_details_attributes][last_name]" size="50" type="text" value=""/> </li> </ol> </fieldset> <fieldset class="inputs"> <ol> <li class="date required date_of_birth" id="application_applicants_attributes_0_personal_details_attributes_date_of_birth_input"> <fieldset> <legend> <span class="label">Date of birth<abbr title="required">*</abbr></span> </legend> <ol> <li> <label for="application_applicants_attributes_0_personal_details_attributes_date_of_birth_1i">Year</label> <select id="application_applicants_attributes_0_personal_details_attributes_date_of_birth_1i" name="application[applicants_attributes][0][personal_details_attributes][date_of_birth(1i)]"> <option value=""/> <option value="2004">2004</option> <option value="2005">2005</option> <option value="2006">2006</option> <option value="2007">2007</option> <option value="2008">2008</option> <option value="2009">2009</option> <option value="2010">2010</option> <option value="2011">2011</option> <option value="2012">2012</option> <option value="2013">2013</option> <option value="2014">2014</option> </select> </li> <li> <label for="application_applicants_attributes_0_personal_details_attributes_date_of_birth_2i">Month</label> <select id="application_applicants_attributes_0_personal_details_attributes_date_of_birth_2i" name="application[applicants_attributes][0][personal_details_attributes][date_of_birth(2i)]"> <option value=""/> <option value="1">January</option> <option value="2">February</option> <option value="3">March</option> <option value="4">April</option> <option value="5">May</option> <option value="6">June</option> <option value="7">July</option> <option value="8">August</option> <option value="9">September</option> <option value="10">October</option> <option value="11">November</option> <option value="12">December</option> </select> </li> <li> <label for="application_applicants_attributes_0_personal_details_attributes_date_of_birth_3i">Day</label> <select id="application_applicants_attributes_0_personal_details_attributes_date_of_birth_3i" name="application[applicants_attributes][0][personal_details_attributes][date_of_birth(3i)]"> <option value=""/> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> <option value="20">20</option> <option value="21">21</option> <option value="22">22</option> <option value="23">23</option> <option value="24">24</option> <option value="25">25</option> <option value="26">26</option> <option value="27">27</option> <option value="28">28</option> <option value="29">29</option> <option value="30">30</option> <option value="31">31</option> </select> </li> </ol> </fieldset> </li> </ol> </fieldset> </ol> </fieldset> </ol> </fieldset> <fieldset class="buttons"> <ol> <li class="commit"> <input class="update" id="application_submit" name="commit" type="submit" value="Save Application"/> </li> </ol> </fieldset> </form>Comments
From top of my head I would suggest:
af.semantic_fields_for :applicants do |pdf|
ivanvanderbyl
Mon Oct 26 20:44:04 -0700 2009
| link
I didn't think of that, but the main reason I did it this way is to apply an .inline-group class to the wrapping fieldset so i can style those fields to appear inline, far from ideal I know.
fieldset inside fieldset? I'm not 100% sure, but I assume very much that that is not W3C standards compliant?
ivanvanderbyl
Mon Oct 26 20:53:48 -0700 2009
| link
fieldset inside fieldset is allowed, but the problem we have above is fieldset directly inside ol without a wrapping li, I guess I'm trying to create a similar markup to that of the date select, to have the name fields inline, and all the others stacked.
I would suggest creating a custom helper instead - most seamless by open up the builder class, but I'm not sure if I speak for everyone else about this.
ivanvanderbyl
Tue Oct 27 14:55:29 -0700 2009
| link
Yes that's always a possibility, but I still think this is be should considered a bug in Formtastic as I'm sure someone else will create similar markup.
justinfrench
Wed Oct 28 14:59:19 -0700 2009
| link
I'm not sure how to fix it off the top of my head, but yes, that's a bug. We don't go two levels deep.
My suggestion would be to hard code the extra lis around the nested fieldset by hand. Not ideal, but not horrible, while I think about the fix.
ivanvanderbyl
Wed Oct 28 15:26:10 -0700 2009
| link
That's what I ended up doing, I'll fork the formtastic, I have a few ideas how we might be able to fix this.
This one is a bit tricky...got ideas, but not any straightforward ones (unless we expect the user to specify that a inputs is just a wrapper which is a bit lazy solution). Anyone working on this?
justinfrench
Wed Nov 18 15:08:12 -0800 2009
| link
we'll let ivan have a play for now, no rush
-
1 comment Created about 1 month ago by dsghcssxfieldset inside fieldset issue in Internet Explorerfor 1.0xHi, I have a problem with the default formtastic.css in IE when using
fields which output a fieldset inside another fieldset, such as a date
field.Other browsers have no problems, but IE (versions 7 and 8 at least)
renders the label to the right of the input.It is fixed for me by removing line 65 of formtastic.css:
form.formtastic fieldset ol li fieldset legend { position:absolute;
width:25%; padding-top:0.1em; }or, more specifically, removing just the position:absolute. I didn't
find any other problem caused by removing this.Here is a test case, could you give it a run and see if you have the
same issue? Hopefully we could get it solved. Thanks.Test case here: http://gist.github.com/217794
Comments
justinfrench
Sat Oct 24 21:00:38 -0700 2009
| link
I'll take a look this week.
-
5 comments Created 7 days ago by activestylusfor 1.0xTranslation arrays not parsed correctlyspecxWhen 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 -
5 comments Created 6 days ago by kjeldahlfor 1.0xSelect input with group_by fails if association name is not a class namespecxI 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?
-
3 comments Created 2 months ago by justinfrenchthe ability to provide :prefix and :suffix stringsfor 1.xxHere's some real-world examples I've found recently:
[input] mt
[input] square meters
AU$ [input] excl. GST
These can all be "solved" with some help/hint text below the input or a verbose label, but I think we should try to figure out a better solution.
Comments
Just a first reflection how it could act...with custom component aspect of it (in HAML)
= f.input do |c| # i.e. block_given? => true, renders LI still = c.field :length # c could be a sort of "input builder", renders INPUT = 'square meters'
...and same pattern applies to a case I just had with Region + City selector aside:
= f.input do |c| = c.field :region = c.field :city
...or "f.wrap do" or similar, but input outputs LI right now so should maybe still be the wrapper.
Sleep on it until it's time for 1.x issues! ;)
I noticed you got a similar - but not identical - approach suggestion in the wiki. A little bit different though.
It would make my day (times 30) if this would get into Formtastic 1.0. I know, I know...it's just that this is soo fundamental stuff, and there seems to be a quite clear picture on how we want to solve this. Bugs me and my partners everyday we work with forms. 8/ With most things near perfect in Formtastic, so missing features like this annoying as a mosquito in a dark room.
-
I think this is really needed for 1.0. It stucks me on daily basis now. It feels like a fundamental feature, just a simple solution would be a relief right now.
Reference: http://groups.google.com.au/group/formtastic/browse_thread/thread/9bb5d808d2a9adbf
Comments
justinfrench
Fri Jul 24 16:40:40 -0700 2009
| link
I'm really cautious about taking on any substantial new work so close to 0.9 (there's one open documentation ticket!). Everything you want to do is 100% "supported" in Formtastic, because you can use your own HTML/ERB/CSS and make your own helpers (or use Rails' built-in ones) to do what you want. Formtastic just isn't making it easier, and there's lots of places in Formtastic where that's still true.
I think there's a few too many open questions about the underlying implementation of the DSL I described in that thread to nail it quickly, but I'll certainly have a play around.
If I'm missing something critical, I'm certainly listening, but for now, I'm tagging this with 1.x.
My argument would be that if everyone is using helpers for exactly this in forms, it's a missing feature. Right now I don't know anyone myself that is not hacking this. I believe that the commit/cancel case catches 90% of cases, so it's a quite descent solution. Helpers solves the other 10%. OK.
justinfrench
Sun Jul 26 00:01:51 -0700 2009
| link
I don't use "cancel" links :)
But I hear you.
-
3 comments Created about 1 month ago by dleeAssociation select should only appear for real associations, not all *_id columnsfor 1.xxRight now, all columns named *_id are being interpretted as association foreign keys. Formtastic should instead only treat those as foreign keys if the column really is a foreign key for an association by looking into the assocation relfections.
Comments
Sounds like a good suggestion, actualyl somebody already suggested that select inputs should check assocation relfections for :conditions too. Both great interesting ideas I believe, but not for 1.0 - I'm quite sure Justin would agree on this. A patch with solid specs is always welcome though. =)
justinfrench
Fri Oct 23 15:21:09 -0700 2009
| link
It's certainly not on my radar for 1.0, but I'll accept a patch for sure. I'm curious as to what kind of columns would have an _id suffix and not be an association, so I'd love to see some examples with the patch or in this ticket so I know why I'm applying it.
-
3 comments Created about 1 month ago by sobrinhoReflect the :conditions option into associationsfor 1.xxHello,
I would to request a new feature, reflect the :conditions options into associations. I have a application like that:
class Company < ActiveRecord::Base validates_inclusion_of :company_type, :in => %w(group_company customer) end class Case < ActiveRecord::Base belongs_to :customer, :class_name => 'Company', :conditions => { 'companies.company_type' => 'customer' } belongs_to :company, :conditions => { 'companies.company_type' => 'group_company' } endAnd I created a form like that (using HAML):
- semantic_form_for Case.new do |f| - f.inputs do = f.input :company, :required => false, :prompt => '- Companies' = f.input :customer, :required => false, :prompt => '- Customers' - f.buttons do = f.submitBut formtastic doesn't reflect the conditions. Well, I arounded that with this:
- semantic_form_for Case.new do |f| - f.inputs do = f.input :company, :required => false, :collection => Company.all(:conditions => { :company_type => 'group_company' } }), :prompt => '- Companies' = f.input :customer, :required => false, :collection => Company.all(:conditions => { :company_type => 'customer' } }),, :prompt => '- Customers' - f.buttons do = f.submitI think that is a great feature and will be very apreciated by users :)
Comments
justinfrench
Thu Oct 01 01:12:31 -0700 2009
| link
Sounds like a good idea!
I guess this is low prio - I never seen one IRL use :conditions on associations, it's really not that common. If it would be a feature, I would suggest to make ValidationReflection plugin more generic...and as I have done some work on ValidationReflection lately, I can say you only have to change a few lines - making it a "ModelReflection" quite easy.
Oh...my bad, no need extend ValidationReflection - everything that's needed is in Rails core:
http://github.com/rails/rails/blob/master/activerecord/lib/active_record/reflection.rb
-
When using
f.input :foo, :as => :textI get what I'd expect, a text area.
However when usingf.inputs :foo, :bar, :as => :text, I'd expect:(either)
A) A text area
B) An error to say it won't cast both :foo and :bar as a text area (Why though?)Comments
justinfrench
Wed Aug 12 03:55:26 -0700 2009
| link
it needs to do "B" or nothing (at least for now), because there's a bunch of input() options that don't make sense on inputs()
or "C": do nothing, which is still viable IMHO because the options you're trying to use on inputs aren't documented to work anywhere, right?
in general, inputs() is supposed to be a shortcut/shorthand to get you something quickly, not a realistic tool for the end result
will happily accept a patch for better documentation, or perhaps raising for unknown args (although I hate maintaining that sort of code), but I'm in no serious hurry on this... tagging with 1.x for now
-
3 comments Created about 1 month ago by DiMarcellosemantic_*_for builder optionfor 1.xxA 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.
-
Tell me please are you going to make dynamic creation of nested form fields like it's done in
http://github.com/ryanb/complex-form-examples (with Prototype) or http://github.com/timriley/complex-form-examples/tree/unobtrusive-jquery-deep-fix2 (with jQuery)?
This feature will be very useful.
Thanks!Comments
justinfrench
Thu Oct 29 13:39:00 -0700 2009
| link
We're not planning on doing anything with Javascript directly until the existing functionality is solid. However, I think others have done part of this work in a fork, and I'd be interested in providing the correct hooks in the mark-up to support an established plugin. Right now, I'd don't want to add Javascript to our code base.
-
In order to use pretty iPhone-style checkbox toggles (Look: http://awardwinningfjords.com/ ), instead of using a plain old boolean_input (which in this case makes an erroneous assumption about how I'd like my label marked up) I had to add this custom input type:
def iphone_toggle_input(method, options) html_options = options.delete(:input_html) || {} html_options = default_string_options(method).merge(html_options) if STRING_MAPPINGS.include?(type) self.label(method, options.slice(:label, :required)) + self.send("check_box", method, html_options) endCertainly, that wasn't a big whoop (once I've ironed out the CSS-kinks), but it'd be nice to be able to just "force" the regular "input_simple" style of label markup rather than the one boolean_input now assumes.
Comments
justinfrench
Fri Jul 03 18:46:35 -0700 2009
| link
The whole of Formtastic makes assumptions about how you want your markup -- that's the point really :) Anyway, in Formtastic 2.0, the plan is that you'll be able to override the underlying markup to suit your own preferences.
Right now, we're trying to get a stable and usable 1.0 out the door, which we've consciously decided should not tackle Javascript or custom inputs / markup / styles, so i'll tag this with the 1.x label to revisit after 1.0.
-
3 comments Created 15 days 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 :)
-
21 comments Created about 1 month ago by lapluviosilla@joséxfor 1.xxi18nxsemantic_fields_for i18n labelsnot surexI use semantic_fields_for a lot to create sub-forms within my "semantic_form_for" forms. There does not appear to be any way to internationalize the inputs inside the "semantic_fields_for" blocks other than specifying the label keys manually. For example:
- semantic_form_for @registration_item do |f| = f.inputs :description, :link, :cost, :instructions = f.input :event, :collection => @events - semantic_fields_for :new_event do |e| = e.inputs :title, :event_date, :summaryI've tried adding a "new_event" key to my i18n language file under en.formtastic.labels.new_event and under en.formtastic.labels.registration_item.new_event, but neither worked.
-Thanks for the great gem/plugin
Comments
Hmm...it could very much be a bug, because there's no spec for I18n-lookups in nested forms - not sure. Let me try to reproduce this case myself.
First off, you have a bug in your code - no form object known to semantic_fields_for
Incorrect:
- semantic_fields_for :new_event do |e|
Correct:
- f.semantic_fields_for :new_event do |e|
This works partly will not be wrapped in a fieldset/list, so this will work for sure:
- f.inputs :for => :new_event do |e| = e.input ... = e.input ...
Justin: f.semantic_fields_for != f.inputs :for => ..., should it not work the same way? Maybe I confused it. I always se f.inputs myself.
lapluviosilla
Wed Oct 14 16:30:33 -0700 2009
| link
That's what I tried at first, but I can't do that because new_event is not a property of registration_item. The way I have it right now works and thats how I used to use it when I used a simple rails "fields_for" before I moved over to formtastic. Rails does not assume that the fields_for block is for a property that belongs to the main resource.
Basically, what my form does is that it lets the user pick an existing event or create a new event that is associated to the registration item he is creating. If he picks an event in the "event" combobox then the new_event is ignored, but if he doesn't pick an event then an event is created using the :new_event param.
Here's an excerpt from my controller:
@new_event = Event.new(params[:new_event]) # If the user didn't choose an existing event then use the "new event" if @belongs_to_event && @registration_item.event.nil? @registration_item.event = @new_event end
lapluviosilla
Wed Oct 14 16:33:23 -0700 2009
| link
In reply to your previous message: "I can't reproduce this. Are you sure that you enabled I18n-lookups in config?":
Yes, I did, but as you said there is no spec for i18n lookups in nested forms. I don't see how its possible given the current i18n format. It would be nice to be able to have a key "en.formtastic.labels.registration_item.new_event.title" for the title field in the new_event fields_for block, but if I do that then it'll just think that "new_event" is an action and not a sub-form.
Could you maybe fork my formtastic test-app and reproduce the case? I'm not entirely on track with this - well it's bed time soon. -_-
http://github.com/grimen/test_app
The thing is, the form builder is only aware of the instance methods you call on the form builder itself: Formtastic cannot be aware of basic form helpers called on the template. Correct me if I'm wrong, Ruby/Rails meta-programming tricks surprised me before for sure. =)
lapluviosilla
Wed Oct 14 17:56:35 -0700 2009
| link
Just forked and added a really crude example that represents the way I have it setup.
http://github.com/lapluviosilla/test_app
FYI: I only modified the HAML view of the new post page.
I made "thing" an independent entity instead of being dependent on "post" and then added a belongs_to :thing to "post". So, basically a thing has many posts even though I didn't add that association to the thing model. I also added a combo box to the new post page so that you can chose an existing thing instead of creating a new one.Got interrupted in the debugging when I was into this, but I managed to notice that the form object (builder.object) is nil, and the lookup paths for your test case is:
nil_class.new.about nil_class.about
Need to figure out why it's nil (@Justin: Do you have a theory?). Either way, the I18n lookup should not look for nil_class - should be ignored.
justinfrench
Sun Oct 18 13:17:56 -0700 2009
| link
Does this need to be addressed for 0.9?
Probably not before 1.0 because this is sort of "should work, but not the most common scenario" case, but I was on nested forms issues recently so did some research on this one. Either way a small justification should be done to avoid too lookup "nil_class" (0.9 I guess), but to solve lapluviosilla's issue later issue.
justinfrench
Sun Oct 18 13:24:48 -0700 2009
| link
Tagged it with 1.x, will gladly accept a patch to address any of these issues sooner, they're a little above my head.
@lapluviosilla: Try this branch if it solves this issue:
http://github.com/grimen/formtastic
My assumption is that this bug just got squashed, but you probably will know best by reviewing it with your affected app.
lapluviosilla
Sat Oct 24 08:15:41 -0700 2009
| link
I tried to checkout your branch, but I get this error:
warning: remote HEAD refers to nonexistent ref, unable to checkout.Another of those gitHub bugs that makes me wipe tears of pain every now and then. Will try to solve it myself, or worst case contact the crew.
OK, now it should work again. Had to re-create the remote branch again to get it to work.
lapluviosilla
Sat Oct 24 11:23:56 -0700 2009
| link
Yes, this helps. Thx! I moved a bit of my code around and now my entire form is correctly translated for now.
However, I still think that there are a few improvements that could be made to make i18n and form naming more flexible. Currently, there is no way to specify "different" i18n keys for nested forms short of specifying labels for each individual attribute. There is also no way of specifying custom keys for forms just like you can with attributes. It would also be great if you could specify the "model class" for the formtastic form builder instead of it trying to infer it. This would allow someone to name their form "new_event" instead of being forced to name it "event".
All of these ideas came to me while trying to debug this issue, so really I think this issue should be divided into 4 issues:
- named models (symbol name of a class instead of an object: :post vs. @post) not able to lookup correct values. <-- Your fix
- Nested form i18n keys to override default model keys. e.g:
labels: event: title: "Default Event Title" registration_item: event: "Nested Event Title" - Custom form i18n key. e.g ":custom_registration_item" vs ":registration_item"
- Specify base model class for formtastic form builder instead of inferring.
Sorry if this is too confusing. If you are interested I'll go ahead and create 3 more issues and add a bit better explanation of how I think the i18n lookups should work. I'll use your current lookup variables as a reference. These are all just "nice to have features" of course, the main bug been fixed now.
OK, well sometimes "nice to have" features just making things too complex to perform just the basics. I'm not sure I agree all of these suggested imporvements would be great jut because of the risk of making things confusing. Right now the Formtastic I18n API handling 80-90% of the cases I would say. I'll revisit this when I get time, but I would suggest starting a discussion in the google group to get other's opinions.
Maybe this issue should be closed when the new I18n-stuff gets merged, and the suggestions moved into issue or google group - as the initial issue is squashed.
lapluviosilla
Sat Oct 24 11:56:32 -0700 2009
| link
Ok, well 3 is the only one I'd really push for, because you are already doing something similar with attributes. If you implement 3 then you can achieve the same effect as 2 by just setting a custom key on the nested form. This feature wouldn't be near as confusing as the other features.
:label is not a good name for the form, but here's an example of how it would work compared to the current custom attribute keys.
- semantic_form_for @event, :label => ":event_user_page" = f.input :name, :label => ":custom_name"OK, just a note...right now you can do custom keys using symbol:
= f.input :name, :label => :custom_name
...which is not true for the form builder itself though, makes sense.
- semantic_form_for @event, :as => :my_event
@Justin/José: What's your opinions on this?
lapluviosilla
Sat Oct 24 12:03:56 -0700 2009
| link
Yes, that is what I meant. It's similar to the custom keys for inputs and it would simplify a lot of things.
justinfrench
Sat Oct 24 16:12:50 -0700 2009
| link
I have no opinion on i18n ;) tagged with @josé
- named models (symbol name of a class instead of an object: :post vs. @post) not able to lookup correct values. <-- Your fix
-
Not 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_:.]+
-
14 comments Created about 1 month 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 way to link a label to the input, which is already taken care of by the "for" attribute. You don;t wrap text inputs, why should checks get special treatment? It also makes for styling hell in IE6 (your *html hacks wont always save you)
Right now I'm working on a styling framework built around formtastic and have almost all browsers behaving nice - except you-know-who. IncompetentExploder makes the checkboxes look all hurt up, and struggling to align. It works MUCH better when those inputs are not nested.
Standards FTW
Comments
justinfrench
Wed Sep 30 14:32:33 -0700 2009
| link
the checkbox inputs are inside the labels not because it's "cheap" (we already have the "for" attribute) but because it's a common markup pattern. I don't have a strong opinion either way, but i'll have a think about it and maybe some others can chime in.
in the meantime i'll re-label your issue to "checkbox inputs should not be nested inside their labels (maybe)"
very keen to hear more about what you're building!
personally, I've found life much more enjoyable when all the IE6 quirks are tackled in an IE6-only stylesheet.
I got to agree with Justin: IE-hacks should not belong to the core "formtastic.css" - rather a "formtastic_ie.css". Actually, it seems developers care less about IE for every day now it seems - at least in Europe. Maybe because of this:
http://gs.statcounter.com/#browser_version-eu-monthly-200810-200909
...oh btw, I'm still thinking of spending an hour or two on a fromtastic_blueprint.css - or even Compass + SASS-based. My guess would be that it'll look better in all browsers, and be a fraction in size and complexity in compare to the current one. Much happened on the CSS framework side since it was made I guess.
activestylus
Thu Oct 01 05:53:40 -0700 2009
| link
Grimen, I have already built exactly what you describe using Compass, you can plug Blueprint, 960 or whatever right in.
I didnt want to push this up so quick (still looks like ASS on IE6), but take a peek and let me know what you guys think.
OK, cool - will try it out some day when I get time. Note though that not everyone uses Compass - as far as I know, many don't. So maybe there should be hardcoded ones (easy to generate based on your templates with Compass though).
...and yea, I wouldn't bother about IE6 at all - even Google officially dropped support for it, among some of the worlds biggest websites.
activestylus
Thu Oct 01 06:54:12 -0700 2009
| link
I leave CSS generation up to Sass. You don't really need compass, but this framework is included in my _base.sass
activestylus
Sun Oct 18 07:13:01 -0700 2009
| link
Thanks for the link grimen - will definitely give it a whirl when I have time
Respected proposers of (non-label-wrapped checkboxes)
Dan Cederholm - Mr. semantics himself I would say
http://books.google.com/books?id=Eli4Z2w8zgkC&pg=PT98&lpg=PT98&dq=dan+cederholm+checkbox&source=bl&ots=kLLPbCpojO&sig=ps5fLVlGkQ5C_h_JlYpXsgyKaLE&hl=en&ei=QajfSr3AIsb3-AbE4JE0&sa=X&oi=book_result&ct=result&resnum=2&ved=0CBEQ6AEwAQ#v=onepage&q=&f=falseHTML Dog - usually very good on semantics
http://htmldog.com/examples/inputcheckboxes.htmlAlso after asking myself why checkbox should be treated differently - really, and seeing what the pros say by doing some research, I think I just switched side: My vote is on non-label-wrapped inputs.
I think I got a scalable win-win solution on this one: Adding an option :wrapped => true/false. It'll be easy to style both cases with help of a class on the LI-element that tells what style is used. Yes/No/Maybe? =)
justinfrench
Sat Oct 24 20:50:16 -0700 2009
| link
I don't like indifference and preferences ;)
If we decide it needs to be the author's choice instead of mine, then it should be a preference, because I can't imagine people wanting the choice on each and every input.
True, I just had a feeling this is the type of thing that will never have consensus - I wish W3C did this for us, they so slow in the turns. =P
activestylus
Sun Oct 25 02:45:15 -0700 2009
| link
+1 for setting a global preference - good idea grimen!
-
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.
-
1 comment Created 21 days ago by grimen@joséxfeature suggestion: Partial-shortcutnot surexBefore:
= render "/designs/image_uploader", :f => f
After (sexier):
= f.partial "/designs/image_uploader"
This is a quite common pattern I've seen, as the new/edit forms are usually similar except for the form_for-args.
Comments
justinfrench
Thu Nov 05 17:19:23 -0800 2009
| link
I hate that pattern, so it doesn't get my vote ;)
-
0 comments Created about 20 hours ago by grimen@joséx@justinxHandle ActiveRecord::MultiparameterAssignmentErrorfor 1.xxFormtastic should be smarter with handling such errors:
http://stackoverflow.com/questions/93277/what-does-activerecordmultiparameterassignmenterrors-mean
Rails is not very smart when it comes to this.
Comments
-
If :collection is set, select should always be default for enum/string-columns
0 comments Created about 18 hours ago by grimen...makes more sense - text field for a collection of values (e.g. if enum is stored as a string)
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
-
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| - 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
-
Per this thread on google:
http://groups.google.com/group/formtastic/browse_thread/thread/648031a11ef3e335Fix is here:
http://github.com/lardawge/formtastic/commit/3b60fc4ab6bbda3d2c51ecf57e179dc6de4cecd2Comments












Well, we just need to add :doc: on these to force that.
Not that simple with rdoc.info from memory, but I have a plan... this is just a placeholder/reminder for me