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

Expose submit event with on=submit:el.action syntax. #3739

Merged
merged 5 commits into from
Jun 30, 2016

Conversation

mkhatib
Copy link
Contributor

@mkhatib mkhatib commented Jun 23, 2016

Not very familiar with action service (can we do deep dive next week on it? 😄).

This works, but not entirely sure if I am missing something or if I should be doing this differently.

  • Add tests

ITI: #3343

@cramforce
Copy link
Member

Should there be events for success and failure states as well?

@@ -72,7 +86,8 @@
<form method="post"
action="/form/html/post"
action-xhr="/form/echo-json/post"
target="_blank">
target="_blank"
on="submit:lightbox1">
Copy link
Contributor

Choose a reason for hiding this comment

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

So, is this a "onsubmit" like in the browser? Or logically a "submit success"? I.e. do we wait for submit to finish?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

browser not success. So this would happen regardless of the result of the submission but not when the submission doesn't actually happen (client-side validation errors would not trigger a submit event) .

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok. In that case, we should just add "submit" even right away, right where we add this.addEvent('tap');. Any reason not to do it there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just figured no reason to listen to that event if the users do haven't included the amp-form. But I guess we're already kinda doing that with document-submit so might as well add it for the events right away.

I was also worried about the sequence in which events handlers will be called, my understanding if the other ones are capture they should be called first, no?

Copy link
Contributor

Choose a reason for hiding this comment

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

Correct. Although needed to be tested. You can also call actionService.trigger() from your existing global submit handler. Or even from both: global and the one in the AmpForm. As long as one even is always sent and no more than one. But I'd generally gravitate toward the global handlers, either via addEvent or global submit handler.

Copy link
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 RFC: Expose submit event with on=submit:el.action syntax. Expose submit event with on=submit:el.action syntax. Jun 25, 2016
@mkhatib
Copy link
Contributor Author

mkhatib commented Jun 27, 2016

Added the submit-success and submit-error PTAL.

* event.
*
* For example, action service shouldn't trigger 'submit' event if form is actually
* invalid. stopImmediatePropagation allows us to make sure we don't trigger it
Copy link
Member

Choose a reason for hiding this comment

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

Well, it depends on registration order. With this registered in capture phase, and the action registered in bubble phase, it doesn't though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not entirely sure if I understand but even with capture, how would you stop the event from propagating to the listener in actions-impl?

It seems for tap event we're using e.defaultPrevented to prevent triggering in actions. But we can't use this with submit event because we always preventDefault when we do xhr submission, so we can't use that signal to prevent action from triggering.

Copy link
Member

Choose a reason for hiding this comment

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

For the XHR it might actually make sense to set a property on the event.

However, what I meant is that when stopImmediatePropagation is important over stopPropagation you need to be super careful about order. But the way you currently set up handlers registration order does not make a difference.

@cramforce
Copy link
Member

I didn't follow the full conversation, but this looks good to me in general. Are you adding tests?

@mkhatib
Copy link
Contributor Author

mkhatib commented Jun 28, 2016

Added tests. PTAL.

@mkhatib
Copy link
Contributor Author

mkhatib commented Jun 30, 2016

@cramforce is this good to go?

@cramforce
Copy link
Member

LGTM

@mkhatib mkhatib merged commit cf60b96 into ampproject:master Jun 30, 2016
@mkhatib mkhatib deleted the submit-action branch June 30, 2016 21:11
jonasmattsson1 added a commit to widespace-os/amphtml that referenced this pull request Jul 5, 2016
* master: (236 commits)
  trim all the columns (ampproject#3894)
  Refactoring: Turn private custom element methods into functions. (ampproject#3882)
  Lower the load priority of ad shaped iframes. (ampproject#3863)
  JsDoc fix (ampproject#3892)
  Add screenshots for Opera to AMP Validator extension. (ampproject#3866)
  Fix renaming of generated JSCompiler_prototypeAlias variable. (ampproject#3887)
  fix typo in amp-sidebar.md (ampproject#3833)
  Validator Roll-up (ampproject#3885)
  [CryptoService] Leverage browser native Crypto API to hash strings. (ampproject#3850)
  Size update (ampproject#3883)
  copy amp-ad docs to builtins (ampproject#3879)
  move doc to extension (ampproject#3878)
  [amp-experiment] Exposes isDismissed() method in AmpUserNotification (ampproject#3832)
  fix action-impl warning on dist (ampproject#3867)
  Add params for microad (ampproject#3827)
  Fixed some A4A tests. (ampproject#3859)
  Updates to colanalytics vendor config for amp-analytics. (ampproject#3849)
  Changes to implement A4A (AMP ads for AMP pages) (ampproject#3534)
  Addresses comment left over from PR#3841 (ampproject#3853)
  Expose submit event with on=submit:el.action syntax. (ampproject#3739)
  ...
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.

3 participants