UserFrosting icon indicating copy to clipboard operation
UserFrosting copied to clipboard

ufForm uses the largely unsupported `set` FormData method.

Open Silic0nS0ldier opened this issue 7 years ago • 14 comments

As documented at MDN, full support for FormData is rare among browsers. This includes the set method used in ufForm. An alternative should be implemented, that gets executed instead if feature detection reveals that the required function is missing.

Silic0nS0ldier avatar May 24 '17 13:05 Silic0nS0ldier

@x00x70 can you look in to this?

alexweissman avatar May 24 '17 14:05 alexweissman

i can look, but am completely stacked right now

ghost avatar May 24 '17 14:05 ghost

No rush!

alexweissman avatar May 24 '17 14:05 alexweissman

So i've looked into this. in its current form it might not be easy to implement. Edge, IE 10 and Safari do not have FormData methods beyond append() and hence cannot access/modify the underlying data in the object. Options:

  • re-implement this for every browser
  • add another function for just unsupported browsers (and browser detecton. seems ugly)
  • wait for browsers to catch up.
  • the set() function is the only thing we use which is not supported. We use the set function for handling the binary check boxes. If we re-implement how we capture checkbox input for binary values, then we no longer need the set()function. This might be a good start: https://stackoverflow.com/a/20570060/7335809

When i originally implemented the formData object, it was to enable image upload via ajax. re-implementing this without a formData object might be a difficult challenge, as i seem to recall i used the formData objects for a reason.

thoughts?

ghost avatar May 24 '17 16:05 ghost

Does library like Dropzone use formData to process uploads? If they do, they probably don't support checkbox anyway and won't be of any help, but if they don't use formData, then they must use something else to handle uploads...

That, or handle checkbox the traditional way php side ? :smiling_imp:

lcharette avatar May 24 '17 17:05 lcharette

Another way could be to append each form input to an empty formData ?

See: https://stackoverflow.com/questions/5392344/sending-multipart-formdata-with-jquery-ajax

lcharette avatar May 24 '17 17:05 lcharette

It looks like .set is only used for the binaryCheckboxes feature anyway, right? I'd like to refactor this aspect of ufForm anyway, since right now we have binaryCheckboxes implemented in two different places.

I'd also like to generalize binaryCheckboxes to some kind of transform API as well, while we're at it.

alexweissman avatar Dec 24 '17 19:12 alexweissman

There does appear to be a polyfill, but I'm not sure how it's supposed to work client-side without Node.

alexweissman avatar Dec 24 '17 20:12 alexweissman

Actually, we may be able to solve this problem (and many others) simply by having ufForm as a wrapper around jQuery Form Plugin's ajaxSubmit method.

alexweissman avatar Dec 25 '17 00:12 alexweissman

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jun 28 '19 00:06 stale[bot]

Still an issue I think?

alexweissman avatar Dec 01 '20 20:12 alexweissman

Well, support for FormData in evergreen browsers has improved substantially since this issue was created. Working on this should only be necessary to support older browsers (e.g. IE11, which MS has since given an expiration date).

Silic0nS0ldier avatar Dec 02 '20 09:12 Silic0nS0ldier

Ok. There are still other reasons for rewriting/redesigning ufForm at some point. I'm not so sure about jQuery Form right now though, because apparently it's not fully compatible with jQuery 3 at the moment. It might be a situation where we can simultaneously rewrite ufForm and contribute to jQuery Form at the same time...

alexweissman avatar Dec 03 '20 15:12 alexweissman

Evidently they'd appreciate the help: https://github.com/jquery-form/form#pull-requests-needed

Silic0nS0ldier avatar Dec 05 '20 04:12 Silic0nS0ldier