Skip to content

Instantly share code, notes, and snippets.

@eramella
Last active August 29, 2015 14:18
Show Gist options
  • Save eramella/d11b5380c874e7e004fd to your computer and use it in GitHub Desktop.
Save eramella/d11b5380c874e7e004fd to your computer and use it in GitHub Desktop.
Custom Styling Directive for Bootstrap
(function(module){
var setupDom = function (element){
var input = element.querySelector("input, textarea, select, custom-directive");
var type = input.getAttribute("type");
if (type !== "checkbox" && type != "radio"){
input.classList.add("form-control");
} //we can add an else to add different classes for radio and checkbox since
//form-control doesn't render nicely with these 2 input types
var label = element.querySelector("label");
label.classList.add("control-label");
element.classList.add("form-group");
};
var link = function(scope, element){
setupDom(element[0]);
};
var forminput = function(){
return {
restrict: "A",
link: link
};
};
}(angular.module("forms")));
<form name="profileForm" ng-model="model.submit()">
<div forminput>
<label for="username">Your user name:</label>
<input type="text" id="username" name="username" placeholder="User name" ng-model="model.user.username">
<custom-directive id="custom" name="custom" value="model.user.custom"></custom-directive>
</div>
</form>
@eramella
Copy link
Author

eramella commented Apr 7, 2015

This was an excellent idea from Scott Allen - AngularJS Playbook that I decided to bookmark for future use

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment