JavaScript-definition of the context of keystrokes (selection of the form of history versus presentation of the form)

I am writing a semi-generic form plugin using jQuery to speed up the development of the project I'm working on.

The plan is that the jTemplates template contains fields, my plugin looks at the template to find any required multilingual resources, requests them from the server and then packs everything into a JavaScript object, which is then passed to the user function on "submit".

Everything works well, except for the standard โ€œwhen input is entered, enter the form codeโ€, which you need to do when you pretend to be in the form:

opts.coreElement.find('input[type=text]').keypress(function(evt) {
    if ((evt.keyCode || evt.which) == 13) {
        opts.coreElement.find('.saveButton').click();
    }
});

The problem is that in Firefox (at least I have not tested other browsers yet), if you previously entered information in a text field with the same name, you get your form history. If you then select one of the suggested values โ€‹โ€‹by pressing enter, it will submit the form. Not very good if you are on the first entry on the page. This is actually quite annoying.

jQuery. , , ASP.NET MVC, , ? , , ? , WebForms ASP.NET, "" ?

, , , ?

+3
3

autocomplete off:

opts.coreElement.find('input[type=text]').each(function() {
     $(this).attr('autocomplete', 'off');
});

(Safari, Firefox, IE).

+2

, [enter] [tab] keydown / .
, keyup keypress, keydown .

+2

The answer from wulong works, but it did not fully answer the question. The proposed solution is to disable the input history of the text field. But is there any way to know that the key event came from the input text or from the story?

0
source

All Articles