Skip to content

Instantly share code, notes, and snippets.

@jordangray
Last active February 1, 2017 17:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jordangray/5910582 to your computer and use it in GitHub Desktop.
Save jordangray/5910582 to your computer and use it in GitHub Desktop.
A simple shim for the HTML5 formaction attribute.
# Test for formaction attribute support in Modernizer.
Modernizr.addTest 'formaction', 'formaction' of document.createElement('input')
# Shim for formaction attributes on buttons and inputs.
$.fn.shimFormAction = ->
return this if Modernizr.formaction
this.each ->
$(this).find 'input,button'
.filter '[formaction!=""][formaction]'
.on 'click', ->
$this = $ this
$this.closest('form').attr 'action', $this.attr('formaction')
true
Modernizr.addTest('formaction', 'formaction' in document.createElement('input'));
$.fn.shimFormAction = function() {
if (Modernizr.formaction) {
return this;
}
return this.each(function() {
return $(this).find('input,button').filter('[formaction!=""][formaction]').on('click', function() {
var $this = $(this);
$this.closest('form').attr('action', $this.attr('formaction'));
return true;
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment