Skip to content

Allow rendering response data in the form success/error messages#3583

Merged
mkhatib merged 6 commits intoampproject:masterfrom
mkhatib:form-templates
Jun 21, 2016
Merged

Allow rendering response data in the form success/error messages#3583
mkhatib merged 6 commits intoampproject:masterfrom
mkhatib:form-templates

Conversation

@mkhatib
Copy link
Copy Markdown
Contributor

@mkhatib mkhatib commented Jun 15, 2016

ITI: #3343

  • Move XHR changes to a different PR

@cramforce
Copy link
Copy Markdown
Member

@dvoytenko should do a quick pass for mustache integration.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why is this in a then block? Can't it be done sync?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I found this work better for testing. I don't really understand exactly why but basically If I rethrowAsync sync after the this.renderTemplate call, the test always fail with the error being thrown, if I try to expect that test to eventually throw it would catch the error but it doesn't seem to test the last block of the test which does the actual expectations inside the timer.promise(0).then.

I can try and debug this some more if you think we should do this sync.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Likely because you are "catching" the UnhandledRejection when thrown async.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

How do we avoid this? I might need to re-write the way I am testing this. Will try to do some more tests here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed this by changing timer.promise(20) to timer.promise(0) in the test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

@mkhatib
Copy link
Copy Markdown
Contributor Author

mkhatib commented Jun 15, 2016

PTAL

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If we introduce submit-error and such attributes - we have to configure CSS for them in our CSS, right? Otherwise, it'd be illogical to whitelist these attributes in validator but not give them any default meaning.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes I think we should. I think it makes sense in these two cases to manage display for the user as well. So basically moving these styles to be provided by amp by default. Des that make sense?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes, specifically form [submit-success] and form [submit-error], right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes exactly.

Copy link
Copy Markdown
Contributor Author

@mkhatib mkhatib Jun 16, 2016

Choose a reason for hiding this comment

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

Should I move the styles into amp-form.css or these should be part of amp.css? Should I do it in the PR? I think the initial display:none needs to go in the amp.css, no?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

At the very least, form [..] {display: none} should be in amp.css to avoid FOUC.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Tracking adding display:block to these containers in amp-form.css in the ITI PR. Will add in next PRs.

@dvoytenko
Copy link
Copy Markdown
Contributor

So, this is LGTM. Just one request to fallback error.responseJson || {}. And please move XHR changes themselves into a separate PR.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

(You'll probably move this to a separate PR, but...) Before attempting to do json() here, we need to check that the Content-Type is actually JSON. The error response doesn't have to follow the same protocol as the successful response and typically doesn't do so.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sent a separate PR #3669

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

@mkhatib mkhatib changed the title Allow rendering response data in the form success/error messages DO NOT SUBMIT: Allow rendering response data in the form success/error messages Jun 16, 2016
@mkhatib mkhatib changed the title DO NOT SUBMIT: Allow rendering response data in the form success/error messages Allow rendering response data in the form success/error messages Jun 21, 2016
@mkhatib mkhatib merged commit 7ffc8e8 into ampproject:master Jun 21, 2016
@mkhatib mkhatib deleted the form-templates branch June 21, 2016 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants