Created
March 7, 2014 17:01
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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 | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Replace "event" with "e"
https://gist.github.com/AndreaPaciolla/9415321#file-ng-submit-coffee-L16