forked from OpenBazaar/OpenBazaar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
angular.module('app').directive("validateBitcoinAddress", function() { | ||
return { | ||
require: 'ngModel', | ||
link: function(scope, ele, attrs, ctrl) { | ||
|
||
ctrl.$parsers.unshift(function(value) { | ||
if(value){ | ||
// test and set the validity after update. | ||
var valid = window.bitcoinAddress.validate(value); | ||
ctrl.$setValidity('validateBitcoinAddress', valid); | ||
} | ||
|
||
// if it's valid, return the value to the model, | ||
// otherwise return undefined. | ||
return valid ? value : undefined; | ||
}); | ||
|
||
ctrl.$formatters.unshift(function(value) { | ||
// validate. | ||
ctrl.$setValidity('validateBitcoinAddress', window.bitcoinAddress.validate(value)); | ||
|
||
// return the value or nothing will be written to the DOM. | ||
return value; | ||
}); | ||
|
||
|
||
} | ||
} | ||
|
||
}); |