Firefox 3.5.2 Refresh (F5) causes the form value to be highlighted for the next field

I'm having a weird problem in Firefox 3.5.2 with the F5 update.

Basically, when I focus on an input field and hit f5, the content of that input field is copied to the next form field after F5 is updated.

But, if you check your HTML source, the values ​​are loaded correctly. I don't have this problem in IE8 or Safari 4.0.3.

The problem doesn't occur if I do a hard refresh or run window.location.refresh (true).

After F5 Refresh: http://i805.photobucket.com/albums/yy339/abepark/after.jpg

Here's an overview of what's going on.

+2


source to share


6 answers


I believe you need to look into the autocomplete attribute , you should set it on the input field. Be careful, however, as this will have two effects.

  • When you refresh the page, it won't remember the old values
  • The default highlighting of already used values ​​in this input field will also be disabled.


If you want to keep the second behavior, you have to re-enable the autocomplete attribute in JS.

+3


source


Browsers can remember the contents of a form field when updating. It can really throw your scripts out if it relies on an initial field value that matches what is in HTML. You can try to prevent it by calling form.reset () at the beginning.



Different browsers have different strategies for detecting when a form or field is the same as on the previous page. If you have conflicting names or names that change on reboot, it is very possible to confuse them. One would have to see how some code would work just like that.

+2


source


In the backend I am using ASP.NET MVC 1.0 with Spark View engine. When I examine the source code after updating F5 in Firefox 3.5.2, the page displays correctly; however, if you look at the page visually, the adjacent form field is populated with the value from the previous field.

I've included enough code so you can just understand what I am trying to do. Again the rendering is good and the final preview / HTML is fine. This is what I see on the screen is wrong. I am using hidden vars; but the problem occurred before using it too.

Note that in the code below, I have two different id fields: "date_ {projectTask.ProjectTaskId}" and "finishDate_ {projectTask.ProjectTaskId}, which gets the visual expression" date_1 "and" finishDate_2 ".

<table>
    <for each="ProjectTask projectTask in projectTasksByProjectPhase">
        <input type="hidden" value="${projectTask.ProjectTaskId}" />
        <tr>
        <td class="date">
            <div class="box">
                <div class="datefield">
                    <input type="text" id="date_${projectTask.ProjectTaskId}" value="${startDate}" /><button type="button" id="show_${projectTask.ProjectTaskId}" title="Show Calendar"><img src="~/Content/yui/assets/calbtn.gif" width="18" height="18" alt="Calendar" ></button>
                </div>
            </div>
        </td>
        <td>
            <div class="box">
                <div class="datefield">
                    <input type="text" id="finishDate_${projectTask.ProjectTaskId}" value="${finishDate}" /><button type="button" id="finishShow_${projectTask.ProjectTaskId}" title="Show Calendar"><img src="~/Content/yui/assets/calbtn.gif" width="18" height="18" alt="Calendar" ></button>
                </div>
            </div>
        </td>
    </tr>
    </for>
    </table>

      

FYI: $ {} are used to display variables in the Spark View engine.

I am also using YUI 2.7 connection to make Ajax calls to update the database for "change" and "enter / tab key press" events. I can verify that the AJAX calls are made correctly and that the form field values ​​are still valid.

The problem comes when I just update F5; for some reason, the "finishDate_1" value is filled with the "date_1" value.

This problem occurs simply by clicking "date_1" and pressing F5; so the adjacent field is just populated even if there are no AJAX calls.

Here is the Javascript code I call at the end of the body "

YAHOO.util.Event.onDOMReady(
    function() {
        var idList = YAHOO.util.Dom.getElementsBy(function (el) { return (el.type == 'hidden'); }, 'input');
        len = idList.length;

        var startDatePickers = new Array();
        var finishDatePickers = new Array();

        for (var i = 0; i < len; i++) {
            var id = idList[i].value
            startDatePickers[i] = new DatePicker("date_" + id, "show_" + id, "cal_" + id);
            startDatePickers[i].valueChanged.subscribe(updateDate, 'S');
            finishDatePickers[i] = new DatePicker("finishDate_" + id, "finishShow_" + id, "finishCal_" + id);
            finishDatePickers[i].valueChanged.subscribe(updateDate, 'F');
        }
    }
} 

      

The form field is copied before any Javascript code is processed because I am calling the Javascript code at the end of the body after all the HTML has been output. So my guess is this is an update issue in Firefox? What do you guys think?

As you can see above, I've created my own calendar date picker objects that allow you to either manually enter a date into the text, or click a button to view the calendar and select a date. Once the date is entered or selected, an AJAX call will be made to update the database at the back end.

Thanks everyone for the quick answers.

0


source


@Anonymous: whoever you are, you are awesome!

@bobince: thanks for the feedback.

I added a dummy form tag with autocomplete = "off" attribute and that solved the problem! I was scratching my head because I didn't get this problem in Safari 4.0.3 or Internet Explorer 8.

<form action="" autcomplete="off">
<!-- my code -->
</form>

      

The values ​​were loading correctly at the end (ASP.NET MVC 1.0 / Spark View engine) and the HTML source reflected this, but the input field values ​​were not filled in correctly. I used YUI and Javascript connection manager to support in-place editing and date picker. I tried to change the XHR call to a GET call instead of a POST call, and this same problem happened.

Anyway, the problem was Firefox was not setting correct values ​​for input fields for F5 updates.

Again, thanks a lot! You guys rock!

0


source


The element id must be unique, if two elements have the same id, this may be the reason why Firefox inserts the same values ​​into ellies that did not have these values ​​in the beginning.

0


source


I had a similar problem related to my question in Input control shows the wrong value even though the validation element shows there is a correct value

The problem occurred for me in Firefox but not Chrome, for some but not all controls on a form, and when I pressed F5 but not ctrl-F5.

The "dummy form" seems to have resolved this for me.

0


source







All Articles