Hello! I am trying to validate presence of one of two form fields. I want to check if there is only one from two possible checkbox selected. I tried to find any hints in documentation, but as a beginner I wasn''t able to invent solution. Best regards! Piotr -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Amador Antonio Cuenca
2011-Feb-15 15:52 UTC
Re: Validates_presence_of on alternative fields
> > Why don''t you use a radiobox?Regards, -- TSU. Amador Cuenca -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 15 February 2011 12:39, Piotroslav <piotroslav-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello! > > I am trying to validate presence of one of two form fields. > I want to check if there is only one from two possible checkbox > selected. > I tried to find any hints in documentation, but as a beginner I wasn''t > able to invent solution.Validation is not on form fields but on data about to be saved to the database. Do you have two columns in the table, one for each checkbox? If so, and only one of them should be selected then reduce it to a single column. As far as the form is concerned you may be better with a radio box as Amador has suggested. If you need them to be checkboxes you could use javascript to clear one when the other is selected. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Well I am using Hobo, which in my case generates form with boolean fields as checkbox. Form is rendered from following dryml: <def tag="win-form" for="Lead"> <form lifecycle="win" merge param="default"> <error-messages param/> <input type="hidden" name="key" value="&this.lifecycle.provided_key" if="&this.lifecycle.provided_key"/><field-list fields="proposal, duration, value, contract_signed, start_at_risk" param/> <div param="actions"> <submit label="#{ht ''leads.actions.win'', :default=>[''Win'']}" param/><or-cancel param="cancel"/> </div> </form> </def> Validation I want to use would be placed in Lead model for specified transition, but if we could do it other way it would be fine too. To be honest I am not sure how to put javascript inside it (but its true it would be much easier with js) nor how to switch to radioboxes. If you know what should I do please give me a hint. I''ll ask similar question on Hobo group. Best regards, Piotr On 15 Lut, 17:08, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> > Validation is not on form fields but on data about to be saved to the > database. Do you have two columns in the table, one for each > checkbox? If so, and only one of them should be selected then reduce > it to a single column. As far as the form is concerned you may be > better with a radio box as Amador has suggested. If you need them to > be checkboxes you could use javascript to clear one when the other is > selected. > > Colin-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.