Created
August 6, 2013 14:03
-
-
Save jmarnold/6164726 to your computer and use it in GitHub Desktop.
fubuvalidation.js + angular.js
This file contains hidden or 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
| (function (angular, fubuvalidation) { | |
| var validation = angular.module('$fubuvalidation', []); | |
| validation.directive('validatedForm', function () { | |
| return { | |
| restrict: "C", | |
| scope: true, | |
| link: function (scope, element, attrs) { | |
| element.activateFormValidation(); | |
| scope.$on('validate:render', function (e, continuation) { | |
| fubuvalidation.Controller.processContinuation(continuation, element); | |
| }); | |
| scope.$on('validate:form', function () { | |
| element.forceValidation(function(notification) { | |
| scope.$emit('validated', notification.toContinuation()); | |
| }); | |
| }); | |
| scope.$on('validate:reset', function (e, continuation) { | |
| element.resetForm(continuation, function (cont) { | |
| cont.forceReset = true; | |
| }); | |
| }); | |
| } | |
| }; | |
| }); | |
| }(angular, jQuery.fubuvalidation)); | |
| (function ($, validation, continuations) { | |
| // You can compose these however you like | |
| validation.Validator = $.fubuvalidation.Core.Validator.basic(); | |
| validation.Processor = $.fubuvalidation.UI.ValidationProcessor.basic(); | |
| validation.Controller = new $.fubuvalidation.UI.Controller(validation.Validator, validation.Processor); | |
| $.fn.activateFormValidation = function () { | |
| return this.each(function () { | |
| validation.Controller.bindEvents($(this)); | |
| }); | |
| }; | |
| $.fn.forceValidation = function (callback) { | |
| return this.each(function () { | |
| validation.Controller.submitHandler($(this)).done(callback); | |
| }); | |
| }; | |
| $.fn.resetForm = function (original, configure) { | |
| return this.each(function () { | |
| var continuation = continuations.create(original || {}); | |
| continuation.form = $(this); | |
| continuation.success = true; | |
| if (angular.isFunction(configure)) { | |
| configure(continuation); | |
| } | |
| var context = new validation.UI.RenderingContext(continuation); | |
| validation.Processor.reset(context); | |
| }); | |
| }; | |
| }(jQuery, jQuery.fubuvalidation, $fubu.continuations)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment