1

I am using ui-select with valdr. I used the following directive to patch the name attribute issue and the valdr for ui-select worked, but the when I change the ui-select value its not updating the message. That is the form element remains in ng-invalid state. Same thing works for other inputs that ain't using ui-select.

This is my directive:

angular.module('app').directive('input', function () {
    var count = 0;
    return {
      restrict: 'E',
      compile: function () {
        return {
          pre: function (scope, element, attrs) {
            // if the input is created by ui-select and has ng-model
            if(element.hasClass('ui-select-search') && attrs.ngModel) {
              var nameAttr = element.parent('.ui-select-bootstrap').attr('name');
              var idAttr = element.parent('.ui-select-bootstrap').attr('id');
              if(nameAttr){
                attrs.$set('name', nameAttr);
              }

              if(idAttr){
                attrs.$set('id', idAttr);
              }

            }
          }
        }
      }
    }
  });
winnyboy5
  • 1,486
  • 3
  • 22
  • 45

0 Answers0