Delegate submit events until amp-form is loaded #6929
Delegate submit events until amp-form is loaded #6929mkhatib merged 8 commits intoampproject:masterfrom
Conversation
| }); | ||
|
|
||
| /** | ||
| * Append ?sleep=5 to any included JS file in examples to emulate delay in loading that |
src/document-submit.js
Outdated
| // the actual submission. For non-XHR GET we let the submission go through | ||
| // to allow _blank target to work. | ||
| if (actionXhr) { | ||
| actionServiceForDoc(form).execute(form, 'submit', null, form, e); |
There was a problem hiding this comment.
i think this should be the last line in this block
extensions/amp-form/0.1/amp-form.js
Outdated
| this.urlReplacement_.expandInputValueSync(varSubsFields[i]); | ||
| } | ||
|
|
||
| // If this wasn't a submission event, trigger form submit. |
There was a problem hiding this comment.
I don't really understand this. Could you explain? Can we split this into two methods?
There was a problem hiding this comment.
Yeah this confusion comes from reusing this method once for actual submit event handling and the other for doing an actual submission flow (triggered by on=form.submit for example).
I couldn't figure out how to refactor the function to reuse the functionality in either cases, but I can think a bit more about it and see if I can simplify it.
There was a problem hiding this comment.
Ok, I split this method to multiple ones for clarity and handling a submission event is now separate from handling a submission action. PTAL 👀
src/document-submit.js
Outdated
| // the actual submission. For non-XHR GET we let the submission go through | ||
| // to allow _blank target to work. | ||
| if (actionXhr) { | ||
| actionServiceForDoc(form).execute(form, 'submit', null, form, e); |
|
@dvoytenko PTAL 👀 |
extensions/amp-form/0.1/amp-form.js
Outdated
| installEventHandlers_() { | ||
| this.form_.addEventListener('submit', e => this.handleSubmit_(e), true); | ||
| this.form_.addEventListener( | ||
| 'submit', e => this.handleSubmitEvent_(e), true); |
There was a problem hiding this comment.
this.handleSubmitEvent_.bind(this)
| * invalid. stopImmediatePropagation allows us to make sure we don't trigger it. | ||
| * | ||
| * | ||
| * @param {?Event=} opt_event |
| event.preventDefault(); | ||
| return; | ||
| } | ||
| if (this.xhrAction_ || this.method_ == 'POST') { |
There was a problem hiding this comment.
Please document why preventDefault is not needed in other situations.
|
@mkhatib Looks good. Just a couple of minor requests. |
|
PTAL 👀 |
9d94522 to
6ca6119
Compare
* master: (310 commits) Update csa.md to remove non-required parameters (ampproject#6902) Add notes about requesting ads ATF and link to demo (ampproject#7037) Remove whitelist for lightbox scrollable validator (ampproject#7034) Delegate submit events until amp-form is loaded (ampproject#6929) Moves closure sha384 into a new extension amp-crypto-polyfill for lazy load (ampproject#7006) Refactor observables in viewer-impl into a map object (ampproject#7004) resizing of margins (ampproject#6824) Use URL replacer from embed for pixel (ampproject#7029) adds support for Gemius analytics (ampproject#6558) Avoid duplicating server-layout (ampproject#7021) Laterpay validator config (ampproject#6974) Validator rollup (ampproject#7023) skeleton for amp-tabs (ampproject#7003) Upgrade post-css and related packages to latest (ampproject#7020) handle unload (ampproject#7001) viewer-integr.js -> amp-viewer-integration (ampproject#6989) dev().info()->dev().fine() (ampproject#7017) Turned on experiment flag (ampproject#6774) Unlaunch ios-embed-wrapper for iOS8 to avoid scroll freezing issues (ampproject#7018) Add some A4A ad request parameters (ampproject#6643) ...
Fixes #6928
Fixes #6916
This also fixes non-xhr submit throguh the
on=action:form.submitsyntax.