Text field magic?

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(
            :url => { :action => 'update'},
            :update => 'message',
            :with => field,
            :condition => "check(this)"
        <%= observe_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’} );

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?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs