backbone.intercept icon indicating copy to clipboard operation
backbone.intercept copied to clipboard

Edge always submits forms

Open jeffijoe opened this issue 9 years ago • 4 comments

This is because

_interceptForms: function(e) {
  if (e.target && e.target.action) { return; }
  e.preventDefault();
},

returns when there's an action. In Edge, if there is no action defined on the form, it defaults to the current URL, therefore bypassing e.preventDefault().

jeffijoe avatar Mar 10 '16 07:03 jeffijoe

hi @jeffijoe what is the expected behavior? that if the e.target.action is the same as the documents url and its edge, preventDefault()? or would that be too open?

linus-amg avatar Jun 09 '16 14:06 linus-amg

The expected behavior is that Intercept will intercept form submissions, but only if they have no actions defined. In Edge, no action means action = current url, and so Intercept always bypasses it.

jeffijoe avatar Jun 09 '16 14:06 jeffijoe

ok, but we wont change the action, the only thing I see which we can do would be to check if the action === url and then not return but continue to prevent, does that sound like a solution?

linus-amg avatar Jun 09 '16 14:06 linus-amg

This is what I did to fix the issue on my end.

// In case Intercept does not catch things for forms (in Edge),
// use our own handler.
$('body').on('submit.interception', 'form', (e) => {
  if ($(e.target).data('bypass')) return;
  e.preventDefault();
});

jeffijoe avatar Jun 09 '16 14:06 jeffijoe