Giter Site home page Giter Site logo

pombredanne / angular-shims-placeholder Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cvn/angular-shims-placeholder

0.0 1.0 0.0 491 KB

Add Angular directive to emulate attribute ´placeholder´ in text and password input fields for browsers, such as IE8 and below

License: MIT License

JavaScript 100.00%

angular-shims-placeholder's Introduction

angular-shims-placeholder

Bower version npm version Build Status devDependency Status

Angular directive to emulate the placeholder attribute on text and password input fields for old browsers, such as IE9, IE8, and below. Also works on textareas and html5 input types.

This directive works in both directions, which means that changing the value from inside the model is honoured in the form.

In comparison to https://github.com/urish/angular-placeholder-shim, this Angular directive is implementend purely on the AngularJS API and does not depend on other libraries, such as jQuery and jquery-html5-placeholder-shim.

Demo

View Demo

Usage

Include

<script src="angular-shims-placeholder.min.js"></script>

into your application.

Add the module as a dependency to your application module:

angular.module('MyAwesomeApp', [/* other dependencies */, 'ng.shims.placeholder']);

That's it. Now, text fields having an attribute placeholder behave almost as native placeholder fields, even on IE8 and below.

Example:

<input type="text" name="email" placeholder="Enter your email" />

Note

Remember to adapt your styles for forms using this placeholder directive. To an empty input field, the class empty is added. So, when defining your styles, use a light grey, or similar, as text-color, to distinguish optically between labels and real input.

Compatibility

This directive is compatible with ngModel, ngDisabled, ngReadonly, ngRequired, ngShow, and ngHide.

If you modify a shimmed input from outside of Angular, use the 'change' event to update the placeholder display. e.g. elem.triggerHandler('change')

Known Issues

  • Ignores text input from drag and drop
  • Does not support modern-style placeholders that persist until text is entered
  • IE8/9: Disabled textareas show the text insertion cursor on hover. This is due to an IE bug.
  • IE8/9: Clearing a filled input while its text is selected can cause the resulting placeholder text to appear selected
  • No way for an individual input to opt out
  • Not tested with ngAnimate
  • Not tested with ngSubmit
  • Not tested with ngClass
  • Not tested with dynamic placeholders e.g. placeholder="{{val}}"

Authors

Jacob Rief
Chad von Nau

License

Released under the terms of MIT License.

Copyright (C) 2013, Jacob Rief [email protected]

angular-shims-placeholder's People

Contributors

akkunchoi avatar cvn avatar jrief avatar rudasn avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.