cssAudio - ActiveCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmloctocatspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              .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.")
            
          
!
            
              @import "nib"

.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
            
          
!
            
              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"
]
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console