Forum: Ruby on Rails Custom validation of form fields?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Andrew C. (Guest)
on 2006-04-14 00:24
I have been looking at the many validates_* methods that we have
available and I am wondering is it possible to create a custom
validation method to be performed on a form field?

I have the following form (remote via ajax)

<%= form_remote_tag :url => {
       :action => 'do_action',
       :id => @pid },
       :before => 'Element.hide("action_div");' %>
<%= text_field_tag "damt", "0", :size => '5' %>
<input type="submit" name="paction" value="Enter Data">
</form>


I would like to make sure the 'damt' field is submitted with only
multiples of a pre-specified amount, say for example it can only be 15,
30, 45, 60, etc

How would I go about creating a custom validates_ method to handle this,
keeping in mind this damt field does not correspond to any database
table data.

( On a side note, I tried doing this browser-side by adding a condition
=> 'verify_amt()' statement to the form but it broke it completely, and
then thinking maybe :condition was mispelled and should be :conditions
(plural) I tried that also and it no longer broke the form but it failed
to do anything useful.... )

Thanks in advance for any help or suggestions you can offer!
-Andy
This topic is locked and can not be replied to.