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

FormData.constructor fails when passed HTMLFormElement in Firefox #587

Closed
rnicholus opened this issue Jul 1, 2014 · 6 comments · Fixed by googlearchive/ShadowDOM#463
Closed
Assignees
Labels

Comments

@rnicholus
Copy link

I ran a very simple test in Firefox 30 OSX: I attempted to pass an HTMLFormElement into a FormData constructor. In the absence of platform.js, the attempt succeeds. As soon as I import platform.js, it fails.

Please see this fiddle for a one-line demo of the issue. When run in Firefox as is, with the console open, you'll see the error. If you remove the platform.js import, it executes without error.

Is Polymer either messing with the FormData constructor, or perhaps HTMLFormElement?

@arv
Copy link
Contributor

arv commented Jul 1, 2014

We are messing with HTMLFormElement.

A temporary work around is to use

ShadowDOMPolyfill.unwrapIfNeeded

@arv arv added the bug label Jul 1, 2014
@arv arv self-assigned this Jul 1, 2014
@rnicholus
Copy link
Author

Where does ShadowDOMPolyfill live? It doesn't seem to exist in the global namespace when I simply import platform.js 0.3.3.

@arv
Copy link
Contributor

arv commented Jul 1, 2014

@sjmiles

Which browser? I think it only gets added if needed so it will not be there for Chrome (or future versions of Firefox).

If my assumption is correct you can do something like the following to make it always work.

var unwrapIfNeeded = function(x) {
  return x;
}
if (typeof ShadowDOMPolyfill !== 'undefined') {
  unwrapIfNeeded = ShadowDOMPolyfill.unwrapIfNeeded;
}

@rnicholus
Copy link
Author

Ah, I didn't check in Firefox and temporarily forgot that Chrome is the only browser that doesn't need to be shimmed here.

Yes, that does seem to work. I'm extending a form element in a custom element I'm developing, and the following condensed version seems to work (where this is the form I'm extending):

var form = window.ShadowDOMPolyfill ? ShadowDOMPolyfill.unwrapIfNeeded(this) : this;
var formData = new FormData(form);

Thanks for your help on this.

arv added a commit to arv/ShadowDOM that referenced this issue Jul 1, 2014
@sjmiles
Copy link
Contributor

sjmiles commented Jul 1, 2014

When using Polymer, you can always use [window.]unwrap in these situations.

var formData = new FormData(unwrap(this));

@rnicholus
Copy link
Author

That makes it much simpler, thanks. Will the recently committed fix be part of 0.3.4?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants