I tried to find examples where the formStateRestoreCallback lifecycle hook could return autocomplete as the second reason argument, but I didn't find anything.
Here is a quote from the specification:
When user agent updates a form-associated custom element's value on behalf of a user or as part of navigation, its formStateRestoreCallback is called, given the new state and a string indicating a reason, "autocomplete" or "restore", as arguments.
To get the reason with restore you just need to refresh the page with a certain custom element on the page (don't forget to use setFormValue)
customElements.define(
"my-input",
class extends HTMLElement {
constructor() {
super();
this.internals_ = this.attachInternals();
this.internals_.setFormValue("sendData", "localData");
}
static get formAssociated() {
return true;
}
connectedCallback() {
console.log("connectedCallback has been invoked");
}
formResetCallback() {
console.log("formResetCallback has been invoked");
}
formStateRestoreCallback(state, mode){
console.log("formStateRestoreCallback:", state, mode);
}
}
);
but what do you need to do to get autocomplete?
Does anyone know if this thing works?
"restore". And even quickly looking at Chromium's source, while they do define both modes, following the call hierarchy we end up at a single hardcodedCustomElement::EnqueueFormStateRestoreCallback(Target(), restored_state,"restore");"restore"works. By the way in that article Ryosuke Niwa writes:Note that WebKit currently has a limitation that only string can be used for the state, and “autocomplete” is not supported yet."autocomplete"case.formResetCallback. I'm not calling for anything :)