# Text field magic?

**URL:** <https://www.ruby-forum.com/t/text-field-magic/122663>\
**Category:** Rails\
**Created:** [December 10, 2007, 2:35pm UTC](https://www.ruby-forum.com/t/text-field-magic/122663 "2007-12-10T14:35:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![msojka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@msojka](https://www.ruby-forum.com/u/msojka)\
**Post date:** [December 10, 2007, 2:35pm UTC](https://www.ruby-forum.com/t/text-field-magic/122663/1 "2007-12-10T14:35:40Z")

</div>

I have a text field. It starts with an initial value from the  
database. If it changes, I save it to the database. This works via  
observe\_field. The field cannot be blank, so if someone deletes the  
contents of the field, I don’t save that value.

However, I also want to reset the field to the previous value (initial  
value or previously saved value) and not leave it blank.

I have code to do this once. But if the field is emptied a second  
time, I cannot get the handler to refresh the field.

Any ideas why it does not work the second time? Or perhaps it is  
working but putting in a null value?

```
        <%= observe_field(
             field,
            :url => { :action => 'update'},
            :update => 'message',
            :with => field,
            :condition => "check(this)"
          )
        %>
        <%= observe_field(
             field,
            :with => field,
            :function => "refresh(this)"
          )
        %>

```

function check( input ) {  
var v = trim( input.getValue() );

if (! v ) {  
return false;  
}

return true;  
}

function refresh( input ) {  
input.element.value = input.element.lastValue;  
input.element.visualEffect( “highlight”,  
{duration: 2.5, queue: ‘end’} );  
}

---

<div class="post-metadata">

**Author:** ![msojka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@msojka](https://www.ruby-forum.com/u/msojka)\
**Post date:** [December 10, 2007, 3:16pm UTC](https://www.ruby-forum.com/t/text-field-magic/122663/2 "2007-12-10T15:16:58Z")

</div>

The problem seems to occur because the onchange handler does not fire.  
Even though I set the field value back, the value is not “sticking,”  
so the field thinks it contains a blank. Hence, when I select the text  
and blank it again, no change, because blank = blank.

What do I need to do to properly reset the field back to a value so  
the second blank differs from what’s there?
