This repository has been archived by the owner on Aug 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
client-side form validation with ng-messages.
remove data prefix from attributes. fix tests
- Loading branch information
1 parent
979c4e5
commit 8015476
Showing
20 changed files
with
274 additions
and
106 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
74 changes: 74 additions & 0 deletions
74
modules/core/client/directives/show-errors.client.directives.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
'use strict'; | ||
|
||
/** | ||
* Edits by Ryan Hutchison | ||
* Credit: https://github.com/paulyoder/angular-bootstrap-show-errors */ | ||
|
||
angular.module('core') | ||
.directive('showErrors', ['$timeout', '$interpolate', function ($timeout, $interpolate) { | ||
var linkFn = function (scope, el, attrs, formCtrl) { | ||
var inputEl, inputName, inputNgEl, options, showSuccess, toggleClasses, | ||
initCheck = false, | ||
showValidationMessages = false, | ||
blurred = false; | ||
|
||
options = scope.$eval(attrs.showErrors) || {}; | ||
showSuccess = options.showSuccess || false; | ||
inputEl = el[0].querySelector('.form-control[name]') || el[0].querySelector('[name]'); | ||
inputNgEl = angular.element(inputEl); | ||
inputName = $interpolate(inputNgEl.attr('name') || '')(scope); | ||
|
||
if (!inputName) { | ||
throw 'show-errors element has no child input elements with a \'name\' attribute class'; | ||
} | ||
|
||
var reset = function () { | ||
return $timeout(function () { | ||
el.removeClass('has-error'); | ||
el.removeClass('has-success'); | ||
showValidationMessages = false; | ||
}, 0, false); | ||
}; | ||
|
||
scope.$watch(function () { | ||
return formCtrl[inputName] && formCtrl[inputName].$invalid; | ||
}, function (invalid) { | ||
return toggleClasses(invalid); | ||
}); | ||
|
||
scope.$on('show-errors-check-validity', function (event, name) { | ||
if (angular.isUndefined(name) || formCtrl.$name === name) { | ||
initCheck = true; | ||
showValidationMessages = true; | ||
|
||
return toggleClasses(formCtrl[inputName].$invalid); | ||
} | ||
}); | ||
|
||
scope.$on('show-errors-reset', function (event, name) { | ||
if (angular.isUndefined(name) || formCtrl.$name === name) { | ||
return reset(); | ||
} | ||
}); | ||
|
||
toggleClasses = function (invalid) { | ||
el.toggleClass('has-error', showValidationMessages && invalid); | ||
if (showSuccess) { | ||
return el.toggleClass('has-success', showValidationMessages && !invalid); | ||
} | ||
}; | ||
}; | ||
|
||
return { | ||
restrict: 'A', | ||
require: '^form', | ||
compile: function (elem, attrs) { | ||
if (attrs.showErrors.indexOf('skipFormGroupCheck') === -1) { | ||
if (!(elem.hasClass('form-group') || elem.hasClass('input-group'))) { | ||
throw 'show-errors element does not have the \'form-group\' or \'input-group\' class'; | ||
} | ||
} | ||
return linkFn; | ||
} | ||
}; | ||
}]); |
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
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
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
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
Oops, something went wrong.
1 comment
on commit 8015476
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Every time so much code is written without a single line of test a programmer dies.
Why is this static?