CodePen

HTML

            
              .row(ng-app="PlaceholderDemoApp" ng-controller="test")
  .form-group.container
    .col-lg-4.form-group
      input.form-control.better-placeholder(type="text" ng-model="text1" placeholder="Default")
    .col-lg-4.form-group.has-error
      input.form-control.better-placeholder(type="text" ng-model="text1" placeholder="Error State, same as 1st and 3rd inputs values. This one is extremely long and is overly so just to show what would happen.")
    .col-lg-4.form-group.has-warning
      input.form-control.better-placeholder(type="password" ng-model="text1" placeholder="Password Text")
  .form-group.container
    .col-lg-4.form-group.has-success
      input.form-control.better-placeholder(type="email" ng-model="text2" placeholder="Email Text")
    .col-lg-4.form-group
      input.form-control.better-placeholder(type="email" ng-model="text2" ng-placeholder="testplaceholder")
    .col-lg-4.form-group
      input.form-control.better-placeholder(type="email" placeholder="Not Ng-Model" value="yay")
    .col-lg-12.form-group
      input.form-control.better-placeholder(type="text" ng-model="text1" placeholder="Error State, same as 1st and 3rd inputs values. This one is extremely long and is overly so just to show what would happen. Even in extreme circumstances that are realistically a bit stupid.")
            
          
!

CSS

            
              .col-lg-4
  position: relative
.better-placeholder
  transition: all 0.5s ease
  &::placeholder
    display: none
    opacity: 0
  &.better-placeholder-active
    padding: 18px 12px 6px 12px
    height: auto
.has-error .better-placeholder-text
  color: #A94442
  &.active
    color: #A94442
.has-success .better-placeholder-text
  color: #3C763D
  &.active
    color: #3C763D
.has-warning .better-placeholder-text
  color: #8A6D3B
  &.active
    color: #8A6D3B
.better-placeholder-text
  transition: all 0.5s ease
  position: absolute
  color: #888
  top: 2px
  margin-left: 12px
  line-height: 20px
  height: 20px
  transform-origin: 0 0
  max-width: 85% /* You have to fiddle with this and it .active replacement depending on size of field */
  margin-right: 12px
  white-space: nowrap
  overflow: hidden
  text-overflow: ellipsis
  &.active
    max-width: 110%
    color: #428bca
    visibility: visible
    transform: scale(.8)
    transform-origin: 0 0
    top: -2px

.row
  margin-top: 40px
            
          
!
? ?
? ?
Must be a valid URL.
+ add another resource
via CSS Lint

JS

            
              angular.module('PlaceholderDemoApp', [])
.directive 'betterPlaceholder', ->
	restrict: 'C'
	require: '?ngModel'
	scope: {}
	link: (scope, element, attrs, ngModel) ->
		isEmpty = (value= if ngModel? then ngModel.$viewValue else element.val()) -> (ngModel? and ngModel.$isEmpty value) or (not ngModel? and (not value or value is ''))
		if attrs.ngPlaceholder?
			scope.placeholder = scope.$parent.$eval attrs.ngPlaceholder
			element.attr 'placeholder', scope.placeholder
			scope.$parent.$watch attrs.ngPlaceholder, (val) ->
				element.attr 'placeholder', val
				placeholder.html val
		else if attrs.placeholder? and attrs.placeholder isnt '' then scope.placeholder = attrs.placeholder
		else throw "better-placeholder requires an ng-placeholder or placeholder attribute"
		
		placeholder = angular.element "<span class='help-block better-placeholder-text'>#{scope.placeholder}</span>"
		element.after placeholder
		placeholder.on 'click', -> element[0].focus()
		
		activate = ->
			element.addClass 'better-placeholder-active'
			placeholder.addClass 'active'
		deactivate = ->
			if isEmpty()
				element.removeClass 'better-placeholder-active'
				placeholder.removeClass 'active'
		
		# catch changes from the DOM
		element.on 'focus', activate
		element.on 'blur', deactivate
		element.on 'change', ->
			if isEmpty()
				element.removeClass 'better-placeholder-active'
				placeholder.removeClass 'active'
			else
				element.addClass 'better-placeholder-active'
				placeholder.addClass 'active'
		if ngModel? then ngModel.$formatters.push (value) ->
			if isEmpty value
				element.removeClass 'better-placeholder-active'
				placeholder.removeClass 'active'
			else
				element.addClass 'better-placeholder-active'
				placeholder.addClass 'active'
			value
		else if not isEmpty() then activate()
.controller 'test', ['$scope', ($scope) ->
	$scope.testplaceholder = "Set Via Scoped Var"
]
            
          
!
Must be a valid URL.
+ add another resource
via JS Hint
Loading ..................