How can I make browser remember form values for autocomplete on ajax submit?

1020 views
Skip to first unread message

aadil khan

unread,
Dec 6, 2016, 6:23:28 AM12/6/16
to Chromium-discuss
I have created a form, which on submit does a ajax call for the submission. It is not a standard form submit. How can I make browser remember form data(not just username and password) for autocomplete? 

Roger McFarlane

unread,
Dec 7, 2016, 3:20:07 PM12/7/16
to PhistucK, ma...@chromium.org, aadil khan, Chromium-discuss
-chromium-htmlt
+chromium-discuss

Adding Mathieu, who has worked on expanding the signals that Chromium uses try and recognize AJAX submit events.

Chromium tries to recognize the submit event, even if you preventDefault and handle the actual submission yourself. Is that a short code snippet you can post that demonstrates the flow that isn't working? Is the initial trigger a submit or a click event?

Thanks!

RogerM


On Tue, Dec 6, 2016 at 5:11 AM, PhistucK <phis...@gmail.com> wrote:
Anyway, I do not think this is appropriate for chromium-html5. chromium-discuss might be more helpful.


PhistucK

On Tue, Dec 6, 2016 at 11:02 AM, aadil khan <aadilk...@gmail.com> wrote:
I did tried that also but it is not working.

On Tue, Dec 6, 2016 at 1:34 PM, PhistucK <phis...@gmail.com> wrote:
I understand that, but you can fire the submit event, call event.preventDefault() and submit it using AJAX instead. The form will not be submitted through the standard HTML mechanism this way, but you might get autofill.


PhistucK

On Tue, Dec 6, 2016 at 9:14 AM, aadil khan <aadilk...@gmail.com> wrote:
I am not firing the submit event. I am making ajax call for submission. It is not a standard form submit.

On Tuesday, December 6, 2016 at 12:40:45 PM UTC+5:30, PhistucK wrote:
I think it remembers them as long as the submit event is fired. Are you using the submit event to event.preventDefault() and send your form otherwise?


PhistucK

On Tue, Dec 6, 2016 at 8:57 AM, aadil khan <aadilk...@gmail.com> wrote:
I have created a form, which on submit does a ajax call for the submission. It is not a standard form submit. How can I make browser remember form data(not just username and password) for autocomplete? 

--
You received this message because you are subscribed to the Google Groups "Chromium HTML5" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-html...@chromium.org.
To post to this group, send email to chromiu...@chromium.org.
Visit this group at https://groups.google.com/a/chromium.org/group/chromium-html5/.
For more options, visit https://groups.google.com/a/chromium.org/d/optout.

--
You received this message because you are subscribed to the Google Groups "Chromium HTML5" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-html5+unsubscribe@chromium.org.
To post to this group, send email to chromiu...@chromium.org.
Visit this group at https://groups.google.com/a/chromium.org/group/chromium-html5/.
For more options, visit https://groups.google.com/a/chromium.org/d/optout.




Mathieu Perreault

unread,
Dec 7, 2016, 4:24:32 PM12/7/16
to Roger McFarlane, PhistucK, aadil khan, Chromium-discuss
Hi, 

Sorry if I'm repeating some of what's been said, but say you have a traditional <form> with a submit button and your javascript does something like

$("#submitbutton").click(function(e) {
// Stop the browser from submitting the form.
e.preventDefault();
                // Do some validation.
                // Do an ajax request to send the form contents.
        });

Chrome indeed captures the data in Autocomplete/Autofill. That would be my recommended way of doing it. You should also be able to call form.submit() and interrupt the submit event. The key thing to remember is that there is to be a form submit event being fired (event if it's prevented later).

Thanks

Jonathan Garbee

unread,
Dec 7, 2016, 4:30:56 PM12/7/16
to ma...@chromium.org, Roger McFarlane, PhistucK, aadil khan, Chromium-discuss
That code sample is exactly what won't work. The recommended way as described to get an ajax form to be stored in autocomplete is:

```
document.querySelector('form').addEventListener('submit', e => {
  event.preventDefault();
  // Do if needed
  // Submit form with ajax.
});
```

This method allows the true submit event to fire to trigger Chromium looking for data to remember for autocomplete/fill. By targeting the click even on the button, you are A) Not catching submissions via the "enter" key in some cases, B) not allowing the form to actually go through the submission process through the engine internals.

--
Chromium Discussion mailing list: chromium...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-discuss

---
You received this message because you are subscribed to the Google Groups "Chromium-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-discu...@chromium.org.

Roger McFarlane

unread,
Dec 8, 2016, 10:57:59 AM12/8/16
to Jonathan Garbee, ma...@chromium.org, PhistucK, aadil khan, Chromium-discuss
+1 to Jonathan's comments.

Map all things that semantically mean "submit" to a submit event (e.g., using a "real" submit button, or calling form.submit() from JS as appropriate). then add a listener to the submit event and preventDefault() to do your own AJAX submit.



PhistucK



PhistucK

To unsubscribe from this group and stop receiving emails from it, send an email to chromium-html5+unsubscribe@chromium.org.
--
--
Chromium Discussion mailing list: chromium...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-discuss

---
You received this message because you are subscribed to the Google Groups "Chromium-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-discuss+unsubscribe@chromium.org.

PhistucK

unread,
Dec 8, 2016, 11:47:16 AM12/8/16
to Roger McFarlane, Jonathan Garbee, ma...@chromium.org, aadil khan, Chromium-discuss
Just a note - form.submit() will actually submit the form using the standard HTML submission method, which is undesirable for this case, as far as I understand.
So <input type=submit> (or <button type=submit>) combined with preventDefault on the submit event should do the trick and still allow AJAX-only submission.


PhistucK
Reply all
Reply to author
Forward
0 new messages