Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛async-input: Fixed NonXHR GET on amp-form with Async Input Elements #20362

Merged
merged 3 commits into from
Jan 18, 2019

Conversation

torch2424
Copy link
Contributor

relates to #19334

Discovered this bug recently, I think it happened from a comment that I forgot to test afterwards, and just now came across it by accidentally breaking my manual testing muscle memory 😂

Previously, the this.form_.submit wasn't getting called because the event was passed in both places (though it was not really needed). Thus I went ahead and made things more clear with a boolean, and all works now.

Thankfully, this bug ONLY affects the Async Input case, and not the regular case 😄

nonxhrgetform

Copy link
Contributor

@cvializ cvializ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

if (this.xhrAction_) {
return this.handleXhrSubmit_(trust);
} else if (this.method_ == 'POST') {
this.handleNonXhrPost_();
} else if (this.method_ == 'GET') {
this.handleNonXhrGet_(event);
this.handleNonXhrGet_(true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add a boolean explainer comment this.handleNonXhrGet_(/*shouldSubmitFormElement*/ true);

@zhouyx
Copy link
Contributor

zhouyx commented Jan 16, 2019

LGTM! Does the bug affect Async var substitution?

@torch2424
Copy link
Contributor Author

@cvializ Thank you! And yes, will definitely fix that.

@zhouyx Nope, this does not affect the var substitution, everything worked correctly, accept for the fact that NonXHRGet never called the form element submit(). Meaning everything was completely ready submit, but just never did 🙃

@@ -2114,7 +2118,7 @@ describes.repeated('', {
'formFields[name]': 'John Miller',
'formFields[email]': 'j@hnmiller.com',
};
expect(form.submit).to.have.been.called;
expect(form.submit).to.have.not.been.called;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am confused, I think form.submit should be called since it's a non-XHR get, and the form.submit call is necessary to submit the request and navigate the browser, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So from my understanding, on Non-XHR Get. The form.submit isn't called in the case where there are no Async Inputs (this test). As the Event itself handles the submission.

However, in the case where there are Async Inputs (not this test), we need to manually call form.submit, as the event was preventDefault(), in order to let the AsyncInput do it's getValue().

Glad you noticed this and asked questions to request changes 😄 Let me know if this makes sense. If this is confusing, perhaps for the Non XHR Tests we should add comments specifying why the form submit should/shouldn't be called? 🤔

Copy link
Contributor

@cvializ cvializ Jan 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I missed that there was an event that was propagating that would eventually cause the page to submit, thanks for explaining! Comments could be good but don't let that block you submitting this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cvializ You are welcome! And sounds good! I'll go ahead and merge this, as I think the amp-form tests need an improvement in general, so I'll cross that bridge when it comes 😂

Thanks for the review!

@torch2424 torch2424 merged commit de0ea8e into ampproject:master Jan 18, 2019
@torch2424 torch2424 deleted the async-input-non-xhr-get branch January 18, 2019 21:27
torch2424 added a commit to torch2424/amphtml that referenced this pull request Jan 30, 2019
torch2424 added a commit that referenced this pull request Jan 30, 2019
Enriqe pushed a commit that referenced this pull request Jan 30, 2019
noranazmy pushed a commit to noranazmy/amphtml that referenced this pull request Mar 22, 2019
…mpproject#20362)

* Fixed the event on the handleNonXhrGet

* Fixed presubmit and tests

* Fixed other Non Xhr Tests, and made PR Comments
noranazmy pushed a commit to noranazmy/amphtml that referenced this pull request Mar 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants