# Altering text field value on form load

**URL:** <https://www.ruby-forum.com/t/altering-text-field-value-on-form-load/169054>\
**Category:** Rails\
**Created:** [May 28, 2009, 8:37pm UTC](https://www.ruby-forum.com/t/altering-text-field-value-on-form-load/169054 "2009-05-28T20:37:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![JannaB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/df788c/32.png) [@JannaB](https://www.ruby-forum.com/u/JannaB)\
**Post date:** [May 28, 2009, 8:37pm UTC](https://www.ruby-forum.com/t/altering-text-field-value-on-form-load/169054/1 "2009-05-28T20:37:43Z")

</div>

Suppose I have a model, ‘Associate’, and it has a string member,  
‘branch’. Sometimes branch can end with a percent sign (%) and  
sometimes not.

I have a form to display the Associate data. In the branch field, I am  
simply putting whatever text is in branch, before (to the left of) the  
input box. In the input box itself, I either want to show the % sign  
if branch ends in %, or, nothing.

How can I specify this? Below is my stab at it – SUppose the branch  
is ‘34%’ , Of course, the way I have it, what shows in the text box is  
the full branch of 34%, wherein, in this case, it should just be %.

\<% form\_for @associate do |f| %\>  
\<%= f.label @associate.branch.split("%") %\>\<%=  
f.text\_field :branch %\>  
\<% end %\>

(In my model, I have a before\_save. which will set branch to that  
original portion of branch left of the %, plus whatever is in the text  
box. In so doing, no one can ever bring themselves up the branch-  
coding tree, see?) -JannaB
