Skip to content

Instantly share code, notes, and snippets.

@AndreaPaciolla
Created March 7, 2014 17:01
Show Gist options
  • Save AndreaPaciolla/9415321 to your computer and use it in GitHub Desktop.
Save AndreaPaciolla/9415321 to your computer and use it in GitHub Desktop.
Rewritten the ng-submit ( directive of angularjs ), to fix the Safari's HTML5 'required' tag non-tollerance.
#
# REWRITTEN NG-SUBMIT DIRECTIVE
# TO FIX THE SAFARI'S HTML5 'REQUIRED' TAG
# NON-TOLLERANCE
#
angular.module("powerhtml").directive("ngSubmit", ->
restrict: "A"
priority: 1
link: (scope, elm, attrs) ->
#
# NG-SUBMIT IS ALREADY ON A FORM TAG
# SO BIND THE SUBMIT EVENT
#
elm.bind( "submit" , (event)->
# CHECK IF THE FORM IS VALID
if !scope[elm.attr("name")].$valid
e.preventDefault()
false
else
# EXECUTE THE FUNCTION ALREADY PASSED IN NG-SUBMIT IN THE PARENT FORM
scope.$apply( attrs.ngSubmit )
)
true
)
@jrobichaud
Copy link

jrobichaud commented Oct 17, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment