'use strict';

angular.module('stormpathIdpApp')
  .directive('formControl', function () {
    return {
      restrict: 'A',
      link: function postLink(scope, element, attrs) {
        var fieldname = attrs.name;
        if(!scope.fields){
          scope.fields = {};
        }
        scope.fields[fieldname] = {
          value: element.val(),
          validationError: false,
          errors: scope.errors || {},
          validate: function(){
            return typeof scope.validate === 'function' ? scope.validate(element) : true;
          }
        };

        scope.clearErrors = function(){
          Object.keys(scope.errors).map(function(k){scope.errors[k]=false;});
        };

        element.on('input',function(){
          scope.$apply(function(scope){
            scope.fields[fieldname].value = element.val();
          });
        });
        scope.$watchCollection('errors',function(a){
          angular.extend(scope.fields[fieldname].errors,a||{});
        });
        scope.$watchCollection('fields.'+fieldname,function(a){
          element.val(a.value);
        });
        scope.$watchCollection('fields.'+fieldname+'.errors',function(a){
          angular.extend(scope.errors,a||{});
        });
      }
    };
  });

@@ -988,116 +988,8 @@
 %7D);%0A
-        scope.$watchCollection('fields.'+fieldname,function(a)%7B%0A          element.val(a.value);%0A        %7D);%0A
     

remove un-necessary element value setter