added my-label-select
authorDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 24 Jan 2013 14:33:53 +0000 (15:33 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 24 Jan 2013 14:33:53 +0000 (15:33 +0100)
app/js/directives.js
test/unit/directivesSpec.js

index 67bec43..ac273fe 100644 (file)
@@ -30,7 +30,7 @@ angular.module('myApp.directives', []).
     };
   }).
 
-  directive('myLabelInput', function() {
+directive('myLabelInput', function() {
     return {
                restrict: 'C',
                compile: function(element, attrs) {
@@ -53,7 +53,31 @@ angular.module('myApp.directives', []).
                        element.replaceWith(html);
                }
     };
-  })
+})
+
+.directive('myLabelSelect', function() {
+    return {
+               restrict: 'C',
+               compile: function(element, attrs) {
+                       var my_class = attrs['class'] || '';
+                       my_class = my_class.replace(/ *my-input */,'');
+                       var m = attrs.ngModel;
+                       var html =
+'  <div class="control-group">'+
+'    <label class="control-label" for="'+m+'">'+attrs.label+'</label>'+
+'    <div class="controls">'+
+'      <select id="'+m+'" ng-model="'+m+'"';
+                       ;
+                       if ( attrs.ngOptions  ) html += ' ng-options="' + attrs.ngOptions + '"';
+                       html += '></select>'+
+'    </div>'+
+'  </div>';
+
+                       element.replaceWith(html);
+               }
+    };
+})
+
 .directive('bsTypeahead', ['$parse', function($parse) {
        'use strict';
 
index 134ff8f..ead1584 100644 (file)
@@ -36,4 +36,17 @@ describe('directives', function() {
       });
     });
   });
+
+  describe('my-label-select', function() {
+    beforeEach(module('myApp.services'));
+    it('div+label+input', function() {
+      inject(function($compile, $rootScope, RegistrationState) {
+               dump( RegistrationState() );
+        var element = $compile('<div><select class="my-label-select" ng-model="m" label="label" ng-options="value for value in RegistrationState()"></select></div>')($rootScope);
+               dump(element.html());
+        expect(element.html()).toMatch(/div.*label.*label.*div.*select.*select.*div.*div/i);
+      });
+    });
+  });
+
 });