diff --git a/gui/app.js b/gui/app.js index ba046244..8029f30b 100644 --- a/gui/app.js +++ b/gui/app.js @@ -648,6 +648,12 @@ syncthing.filter('shortPath', function () { } }); +syncthing.filter('clean', function () { + return function (input) { + return encodeURIComponent(input).replace(/%/g, ''); + } +}); + syncthing.directive('optionEditor', function () { return { restrict: 'C', @@ -680,3 +686,25 @@ syncthing.directive('uniqueRepo', function() { } }; }); + +syncthing.directive('validNodeid', function() { + return { + require: 'ngModel', + link: function(scope, elm, attrs, ctrl) { + ctrl.$parsers.unshift(function(viewValue) { + if (scope.editingExisting) { + // we shouldn't validate + ctrl.$setValidity('validNodeid', true); + } else { + var cleaned = viewValue.replace(/ /g, '').replace(/-/g, '').toUpperCase().trim(); + if (cleaned.match(/^[A-Z2-7]{52}$/)) { + ctrl.$setValidity('validNodeid', true); + } else { + ctrl.$setValidity('validNodeid', false); + } + } + return viewValue; + }); + } + }; +}); diff --git a/gui/index.html b/gui/index.html index 057e1615..a75f6765 100644 --- a/gui/index.html +++ b/gui/index.html @@ -125,13 +125,13 @@