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'} ); }