# Doint something with each field in form as it is entered

**URL:** <https://www.ruby-forum.com/t/doint-something-with-each-field-in-form-as-it-is-entered/182599>\
**Category:** Rails\
**Created:** [January 30, 2010, 8:02pm UTC](https://www.ruby-forum.com/t/doint-something-with-each-field-in-form-as-it-is-entered/182599 "2010-01-30T20:02:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [January 30, 2010, 8:02pm UTC](https://www.ruby-forum.com/t/doint-something-with-each-field-in-form-as-it-is-entered/182599/1 "2010-01-30T20:02:26Z")

</div>

Is there a callback or some mechanism that will allow me to modify a  
view once a field in a form is finished … asumming that there are  
multiple fields in a form.

As a silly example, let’s say the bacground of the filed is white by  
default … but once the user goes on to the next field, then make the  
background of that field red if the number of characters in the field is  
even.

---

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [January 30, 2010, 10:42pm UTC](https://www.ruby-forum.com/t/doint-something-with-each-field-in-form-as-it-is-entered/182599/2 "2010-01-30T22:42:58Z")

</div>

On Sat, Jan 30, 2010 at 2:02 PM, Ralph S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Is there a callback or some mechanism that will allow me to modify a  
> view once a field in a form is finished … asumming that there are  
> multiple fields in a form.
> 
> As a silly example, let’s say the bacground of the filed is white by  
> default … but once the user goes on to the next field, then make the  
> background of that field red if the number of characters in the field is  
> even.

Well this would almost certainly have to be done in the browser using  
JavaScript so it’s not really a Rails question.

Most Rails apps use either the Prototype JavaScript framework (since  
that’s what the ajax helpers use), although the modern trend seems to  
be to use jQuery (and Rails 3 will make changing JavaScript frameworks  
much easier).

If you google for

prototype field validation  
and  
jquery field validation

you’ll come up with serveral plugins for both frameworks.

–  
Rick DeNatale

Blog: [http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)  
Twitter: [http://twitter.com/RickDeNatale](http://twitter.com/RickDeNatale)  
WWR: [http://www.workingwithrails.com/person/9021-rick-denatale](http://www.workingwithrails.com/person/9021-rick-denatale)  
LinkedIn: [Rick DeNatale - Developer - IBM | LinkedIn](http://www.linkedin.com/in/rickdenatale)
