Skip to content

Instantly share code, notes, and snippets.

@neilbo
neilbo / nomatch.css
Created September 22, 2014 14:04
Show an error when inputs match
.help-block {
display: none;
}
.has-error .help-block {
display: block;
}
@neilbo
neilbo / capitalise-directive.js
Created September 22, 2014 13:49
Angular Comes with upper and lower case directives, so here's a capitalise directive
angular.module('myApp').
filter('capitalise', function() {
return function(input) {
return (!!input) ? input.replace(/([^\W_]+[^\s-]*) */g, function(txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
}) : '';
};
});
/**
* Custom submit directive that will only submit when all the validation has passed
* for all the fields. This extends on the ng-submit directive provided by AngularJS.
*
* This directive will also remove the 'pristine' flag from all the fields when
* hitting submit, allowing the form to display no errors until the submit button
* is clicked/enter is pressed.
*
* The variable 'app' is the instance of a module.
* E.g. var app = angular.module('my-app', []);
@neilbo
neilbo / creditcardmask.js
Created September 10, 2014 03:59
Mask Credit Card xxx-xxxx-xxxx-4567
app.filter('creditcard', function(){
return function(cc, maskChar, sep){
if(!sep)
sep = '-';
var maskedNum = Array(cc.length - 3).join(maskChar) + cc.substr(cc.length - 4, 4);
maskedNum = maskedNum.substring(0, 4) + sep +
maskedNum.substring(4, 8) + sep +
maskedNum.substring(8, 12) + sep +
maskedNum.substring(12, 16);
@neilbo
neilbo / ngEnter.js
Last active August 29, 2015 14:06 — forked from EpokK/ngEnter.js
app.directive('ngEnter', function() {
return function(scope, element, attrs) {
element.bind("keydown keypress", function(event) {
if(event.which === 13) {
scope.$apply(function(){
scope.$eval(attrs.ngEnter);
});
event.preventDefault();
}
@neilbo
neilbo / disable-space.js
Created September 3, 2014 11:00
disable space bar angular directive
app.directive('ngSpace', function() {
return function(scope, element, attrs) {
element.bind("keydown keypress", function(event) {
if(event.which === 32) {
scope.$apply(function(){
scope.$eval(attrs.ngSpace);
});
event.preventDefault();
}