do a custom validation in your model
def validate
if serial_number.nil?
errors.add(''field1'', "Sorry field1 cant be blank
when using a serial
number") if field1.nil?
errors.add(''field2'', "Sorry field2 cant be blank
when using a serial
number") if field2.nil?
else
errors.add(''serial_number'',"Sorry serial number must
be between 1 and
64000") if serial_number < 1 || serial_number > 64000
errors.add(''field1'', "Sorry field1 must be blank
when using a serial
number") if ! field1.nil?
errors.add(''field2'', "Sorry field2 must be blank
when using a serial
number") if ! field2.nil?
end
end
quick and dirty but should come close :-) Sometimes you have to use
field.nan? instead of nil? if the value is a number, at least in my
experiences. Not sure why types of data is in your fields.
adam
On 3/21/06, Pete <miggyx@peteslan.net> wrote:>
> Hi,
>
> I''ve got an interesting one here :)
>
> I have a form with three fields :
>
> serial_number
> initial
> surname
>
>
> now, if serial_number is entered, it must be between 1 and 64000. If
> it''s filled in, the other two fields must be blank. If
serial_number is
> left blank then the other two boxes must be filled.
>
>
> Any suggestions?
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060321/4281a483/attachment-0001.html