:validator=>false ignored on f.select()?
can I have more info?
I'm using these gems to get the i18n patch:
gem 'client_side_validations', '~> 3.2.0.beta.1'
gem 'client_side_validations-mongoid', '~> 2.4.0.beta.2'
mongoid model:
validates :subject, :inclusion => {:in => %w(earth life phys)}
Form helper:
<%= f.select(:subject, [['physical', 'phys'], ['earth'], ['life']], :prompt => act.new?, :validate => false) %>
CSV injection:
<script>window.ClientSideValidations.forms['edit_act_4f2202a5bf079c0ce4000008']
= {"type":"ActionView::Helpers::FormBuilder","input_tag":"<div
class=\"field_with_errors\"><span id=\"input_tag\" /><label for=\"\"
class=\"message\"></label></div>","label_tag":"<div
class=\"field_with_errors\"><label id=\"label_tag\"
/></div>","validators":{"act[title]":{"presence":{"message":"can't be
blank"}},"act[status]":{"inclusion":{"message":"is not included in the
list","in":["draft","pub"]}},"act[subject]":{"inclusion":{"message":"is
not included in the list","in":["earth","life","phys"]}}}};</script>
Another oddity is that act[status] doesn't block form submission even though it fails inclusion validation. Must be because I'm using radio buttons for it. I didn't set :validate=>false but I've verified :validate=>false works with radio buttons.
Since I need patches for i18n, redundant callbacks, and this, which version should I get?
Can you try using HEAD instead of the gem?
gem :client_side_validations, :git => 'git://github.com/bcardarella/client_side_validations.git'
For both client_side_validations and client_side_validations-mongoid?
On Thu, Jan 26, 2012 at 6:46 PM, Brian Cardarella [email protected] wrote:
gem :client_side_validations, :git => 'git://github.com/bcardarella/client_side_validations.git'
no, just client_side_validations
On Thu, Jan 26, 2012 at 9:50 PM, Ken Keller [email protected] wrote:
For both client_side_validations and client_side_validations-mongoid?
On Thu, Jan 26, 2012 at 6:46 PM, Brian Cardarella [email protected] wrote:
gem :client_side_validations, :git => 'git://github.com/bcardarella/client_side_validations.git'
Reply to this email directly or view it on GitHub: https://github.com/bcardarella/client_side_validations/issues/264#issuecomment-3681155
fixed redundant callbacks inclusion validator
not fixed f.select(..., :validate => false)
I noticed some chatter about numericality validation when input field is blank. mongoid sets the number to nil in this case. It is a convenient use case because otherwise the model needs another field:
qty_known: Boolean qty: Integer
and the corresponding form would look odd:
Quantity Known: [unchecked box] Quantity: [ ]
or the 2nd field would be hidden unless the first was checked.
A purist wouldn't map a persistent model to a form directly anyway--rather a "UI model" would be introduced. This doesn't appear to be the Rails Way.
On Thu, Jan 26, 2012 at 6:52 PM, Brian Cardarella [email protected] wrote:
no, just client_side_validations
On Thu, Jan 26, 2012 at 9:50 PM, Ken Keller [email protected] wrote:
For both client_side_validations and client_side_validations-mongoid?
On Thu, Jan 26, 2012 at 6:46 PM, Brian Cardarella [email protected] wrote:
gem :client_side_validations, :git => 'git://github.com/bcardarella/client_side_validations.git'
Reply to this email directly or view it on GitHub: https://github.com/bcardarella/client_side_validations/issues/264#issuecomment-3681155
Reply to this email directly or view it on GitHub: https://github.com/bcardarella/client_side_validations/issues/264#issuecomment-3681166
Should I continue w/ this? gem "client_side_validations", :git => 'git:// github.com/bcardarella/client_side_validations.git' gem 'client_side_validations-mongoid', '~> 2.4.0.beta.2'
On Thu, Jan 26, 2012 at 9:20 PM, ken keller [email protected] wrote:
fixed redundant callbacks inclusion validator
not fixed f.select(..., :validate => false)
I noticed some chatter about numericality validation when input field is blank. mongoid sets the number to nil in this case. It is a convenient use case because otherwise the model needs another field:
qty_known: Boolean qty: Integer
and the corresponding form would look odd:
Quantity Known: [unchecked box] Quantity: [ ]
or the 2nd field would be hidden unless the first was checked.
A purist wouldn't map a persistent model to a form directly anyway--rather a "UI model" would be introduced. This doesn't appear to be the Rails Way.
On Thu, Jan 26, 2012 at 6:52 PM, Brian Cardarella < [email protected]
wrote: no, just client_side_validations
On Thu, Jan 26, 2012 at 9:50 PM, Ken Keller [email protected] wrote:
For both client_side_validations and client_side_validations-mongoid?
On Thu, Jan 26, 2012 at 6:46 PM, Brian Cardarella [email protected] wrote:
gem :client_side_validations, :git => 'git:// github.com/bcardarella/client_side_validations.git'
Reply to this email directly or view it on GitHub:
https://github.com/bcardarella/client_side_validations/issues/264#issuecomment-3681155
Reply to this email directly or view it on GitHub:
https://github.com/bcardarella/client_side_validations/issues/264#issuecomment-3681166
I think I've found the problem here:
#client_side_validations-3.0.12/lib/client_side_validations/action_view/form_builder.rb
#Lines 58-61
def select_with_client_side_validations(method, choices, options = {}, html_options = {})
apply_client_side_validators(method, html_options)
select_without_client_side_validations(method, choices, options, html_options)
end
The problem here is that apply_client_side_validators method expects html_options to include :validate, but in fact it is the options parameter that contains :validate. This could be easily fixed by changing html_options to options in the second line of code above, but then the apply_client_side_validators method can't merge in the new data-validate attribute into html_options. I believe the apply_client_side_validators method will need to be restructured to account for the anomoly with select fields.
Workaround for now:
f.select :attribute_name, options_array, {:prompt => "Please select"}, {:validate => true}
This makes sure the client_side_validations finds the :validate attribute in html_options
Also note: Issue #200 is clearly a bug and MUST be fixed if you want :validate => true to be recognised if you have a conditional on your select attribute.
[Apologies for not profferring a pull request for this, I have no idea how to even start to go about that.]
Fixed, very sorry it took so long
When using HAML, the proposed solution raises a syntax error. The following worked for me on an input:
f.input :attribute_name, input_html => {:validate => true}