my-label-input directive
[angular-drzb] / app / js / directives.js
index cac0c3c..88d5653 100644 (file)
@@ -25,6 +25,30 @@ angular.module('myApp.directives', []).
                        if ( attrs.bsTypeahead )  html += ' bs-typeahead="'+attrs.bsTypeahead+'"';
                        if ( attrs.dataItems )  html += ' data-items="'+attrs.dataItems+'"'; // for typeahead
                        html += '/></div>';
+                       element.replaceWith(html);
+               }
+    };
+  }).
+
+  directive('myLabelInput', function() {
+    return {
+               restrict: 'C',
+               compile: function(element, attrs) {
+                       var my_class = attrs['class'] || '';
+                       my_class = my_class.replace(/ *my-input */,'');
+                       var my_type  = attrs['type']  || 'text';
+                       var m = attrs.ngModel;
+                       var html =
+'  <div class="control-group">'+
+'    <label class="control-label" for="'+m+'">'+attrs.label+'</label>'+
+'    <div class="controls">'+
+'      <input type="'+my_type+'" id="'+m+'" ng-model="'+m+'" placeholder="'+attrs.placeholder+'"'
+                       ;
+                       if ( attrs.ngRequired ) html += ' ng-required="' + attrs.ngRequired + '"';
+                       html += '>'+
+'    </div>'+
+'  </div>';
+
                        element.replaceWith(html);
                }
     };