views:

979

answers:

2

So I've inherited this legacy rails codebase and there's a bug i need to fix where a given form is retaining values (that have not yet been saved to the DB) even after Page Refresh.

Use Case: User fills data in form but does not press submit. User Clicks refresh button on browser. The Values in the form are retained instead of refreshing the whole page.

Any ideas where I can start looking? In my brief, limited Rails experience, this is not the sort of thing that happens by default, so it must be coded somewhere?

A: 

Tell user to press CTRL+F5

-- edit if you can't tell the user to press CTRL+F5 (which always in my experience works unless the browser is buggy, or unless something else is going wrong), just trip form.reset() in the onload event. This will clear the fields in the form to the default values. If you have default values in the fields though, (like <input type="text" value="enter name here" />) then when you trip .reset(), it will reset to the default value.

bobobobo
+3  A: 

Sometimes browsers will do this. (I'm not talking about auto-fill drop-downs, which browsers also do... just talking about forms that are partially filled out, never submitted, and are then refreshed).

Make sure the values in the fields are actually coming from your Rails app by checking the HTML source window.

Values provided by the browser due to previous entry won't be in the VALUE attribute, but server-provided ones will be.

Some options for avoiding this might be:

  • Send the user to the form using a POST. Thus, any refresh results in a "do you want to resubmit" etc. I don't think the browser will pre-fill any fields in this situation (same as when a user posts and then hits the back button).
  • Use the onload() event to wipe out the form field values.

There's probably a simpler solution... Ctrl-F5 sometimes does the trick, but I think I've seen even that not work before.

richardtallent