# Auto\_complete and validate

**URL:** <https://www.ruby-forum.com/t/auto-complete-and-validate/132168>\
**Category:** Rails\
**Created:** [March 17, 2008, 3:53pm UTC](https://www.ruby-forum.com/t/auto-complete-and-validate/132168 "2008-03-17T15:53:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [March 17, 2008, 3:53pm UTC](https://www.ruby-forum.com/t/auto-complete-and-validate/132168/1 "2008-03-17T15:53:58Z")

</div>

I am trying to validate a phone number when it is update. The way that  
it is updated is through an auto\_complete\_\_text\_field and what I tried  
is to have:

validates\_format\_of :h\_phone, :with =\> /(?[0-9]{3})?-[0-9]{3}-[0-  
9]{4}/, :message =\> “- Phone numbers must be in xxx-xxx-xxxx format.”,  
:on =\> :update

in my model, but I think that an update using a auto\_complete\_text\_field  
isn’t done via an update?

I tried putting that same code in my controller but validate\_format\_of  
is part of the ActiveBase class. I guess my question is how do I  
validate using an auto\_complete\_text\_field or is their another way to  
accomplish the same thing just in a differnt way. Thx,

-S

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [March 17, 2008, 3:59pm UTC](https://www.ruby-forum.com/t/auto-complete-and-validate/132168/2 "2008-03-17T15:59:02Z")

</div>

Shandy N. wrote:

> I am trying to validate a phone number when it is update. The way that  
> it is updated is through an auto\_complete\_\_text\_field and what I tried  
> is to have:

Sorry, I’m using an in\_place\_editor\_field not an auto\_complete - had to  
many things going on at once. Thanks again,

-S

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [March 17, 2008, 4:41pm UTC](https://www.ruby-forum.com/t/auto-complete-and-validate/132168/3 "2008-03-17T16:41:24Z")

</div>

you can use in\_place\_edit instead of in\_place\_edit\_field…  
using in\_place\_edit you can customize the validation…something like  
this  
first thing is create a span of id=“attr\_name” next  
\<%= in\_place\_edit “attr\_name”, {:url =\> url\_for(:action=\> “provide  
action” , :id =\> “optional id parameter”) , :script=\>true } %\>  
remember the script =\> true says that u can now use the rjs methods  
in ur action…then in your action when you update the attribute by  
saying attribute.save check whether there attr.new\_record exist… if  
it does then throw an error message using errors.on. Dont forget to  
replace the new value which is in params[:value] with the span id  
attr\_name using page.replace\_html “attr\_name”, params[:value]  
I think that should work.

On Mar 17, 7:59 pm, Shandy N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
