rails / jquery-ujs

Ruby on Rails unobtrusive scripting adapter for jQuery
MIT License
2.61k stars 508 forks source link

Force `data-remote="true"` on a link? #476

Closed bboe closed 7 years ago

bboe commented 7 years ago

Is it possible to disable other forms of opening links (middle click, cmd+click, etc)? We recently discovered a large handful of MissingTemplate exceptions for requests which appear to originate when our customers are opening a link in a new window or tab whose path is intended to return only responses to xhr requests.

One solution for us is to replace all such instances of data-remote on links with some other approach (e.g., not using links, or not using the href attribute), but it would be nice if there was a way to disable the unwanted behavior completely.

Perhaps this library could support a data-href field and look to that if href isn't provided?

rafaelfranca commented 7 years ago

This is outside of the scope of this library. You may be able to define your own event handlers for click and prevent users to open them in new windows although I consider this bad UX. I'd recommend to take a progressive enhancement approach or not use links at all for those cases.

bboe commented 7 years ago

I'd recommend to take a progressive enhancement approach or not use links at all for those cases.

Yes, I think that's the way to go. Thanks.