Git Product home page Git Product logo

placeholders.js's People

Contributors

christianvuerings avatar cwoolum avatar daniel-franz avatar jonhinson avatar markcarlson avatar marklazz avatar ywen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

placeholders.js's Issues

IE8 placeholders for password (acceptable fix? optional fix?)

IE8 hides text of password. I rather think it should not show it at all as it is very confusing for the user. One can chose to remove password from validTypes array, but then it does not work for IE9 either.

My solution was to modify showPlaceholder like this to make a check if it was possible to change type of password to text.

I basicly moved to "set value" part to after the changeType was called. If changeType fails the method returns false instead and never sets the value.

function showPlaceholder(elem) {
        var type,
            maxLength,
            val = elem.getAttribute(ATTR_CURRENT_VAL);
        if (elem.value === "" && val) {

            // If the type of element needs to change, change it (e.g. password inputs)
            type = elem.getAttribute(ATTR_INPUT_TYPE);
            if (type) {
                elem.type = "text";
            } else if (elem.type === "password") {
                if (Utils.changeType(elem, "text")) {
                    elem.setAttribute(ATTR_INPUT_TYPE, "password");
                }
                else
                {
                    return false;
                }
            }


            elem.setAttribute(ATTR_ACTIVE, "true");
            elem.value = val;
            elem.className += " " + placeholderClassName;

            // Store and remove the maxlength value
            maxLength = elem.getAttribute(ATTR_MAXLENGTH);
            if (!maxLength) {
                elem.setAttribute(ATTR_MAXLENGTH, elem.maxLength);
                elem.removeAttribute("maxLength");
            }



            return true;
        }
        return false;
    }

Hitting escape twice in IE causes password fields to be plain text

If using focus and blur to hide/show placeholder text rather than keydown Escape is not considered a bad key and there is no keypress handler. This allows IE to perform its default behavior clearing form text then if you tab into the password field anything you type will be clear text.

Your gist appears to use the keydown event listener which behaves better as it does preventDefault on pressing the escape button.

jQuery#val returns placeholder text

when using jQuery $('input[placeholder]').val() it returns the place holder text.
this is bad for scripts that depend on val() returning an empty string

Password input placeholders do not work in IE < 9

In IE versions less than 9, the password placeholder fields are replaced with dots, instead of the placeholder text. When this happens, it looks like the password box is already filled in.

Basically, instead of "Enter Password" you'll see "**************".

I have confirmed this behavior when using IE9 in IE8 mode as well as standard IE7 and IE8 browsers using http://www.browserstack.com/.

Jquery plugin

Hi James,

Thanks for this awesome script, this is very usefull (even in IE8, :D)!

Is there any forecast for convert this script in a jquery plugin?

Regards,
Giolvani

Error when enabling/disabling all elements

If I make the following call:
Placehoders.disable()

I get a JS error which in IE9 reads "Unable to get property 'length' of undefined or null reference"

The ultimate cause is here:
// If an element was passed in, get all affected descendants. Otherwise, get all affected elements in document
inputs = node ? node.getElementsByTagName("input") : inputs;
textareas = node ? node.getElementsByTagName("textarea") : textareas;

Outer inputs and textareas variables are shadowed by the variables declared in a function so there is no way to access them and because of this if there is no node passed in, the same value the variables had (undefined) is assigned back to them.

IE8 form 'reset' button removes placeholders

If your form has input type="reset" button, clicking on this removes all the placeholders - they only reappear onblur.

This is obviously a bug, but I suppose #resetbutton.onclick=Placeholder.init or similar should fix it pretty easily.

Thanks.

IE8: returning value

I'm developping an App in IE8 with yui3.
With the onblur event of an input node I check if the value is empty or not to act on the input...
When I use plcaeholders instead of an empty value ('')' I will get the placeholder text. (Same code works fine with IE9 and latest Chorme)

node-input.on('blur', function(e) {
    if (e.target.get('value') != '') {
        // do someting
    } else {
        // do someting else
    }
}, this);

Is there a way to deal with that situation?
Probably it is not a convenient way to wirte the placeholder text directly into the input...

Thanks for Help!
Felix

Check for placeholder support is always returning false

Hi, I'm testing the polyfill in chrome 21 and it's also loading.

Checking the source, I see that you are checking for placeholder support like this:

if (!test.placeholder)

But this condition also returns true when the value of placeholder is "" (as in chrome), so even when chrome has support for placeholder it is loading the polyfill. I think the condition should be something like if (test.placeholder === undefined)

Bower dependencies

I'm using bower to download the lib and used it. But I'm not able to find the proper .js to include in my webpage. Could you please but the assets in the github repository?

does not work on type="number"

I just applied this to a form I am working on and the placeholder text in input type="number" fields did not display by default. it only displayed after I selected and deselected the field or entered and removed data.

Write adapters for common DOM libraries

A common issue with Placeholders.js is "my DOM library method returns the value of the placeholder text instead of the empty string" (see #14 and #38 for examples).

A possible solution is to write a suite of adapters that monkey-patch the methods in question of various DOM libraries and return the empty string when appropriate, delegating back to the original method otherwise.

Libraries that should be covered:

  • jQuery
  • YUI
  • Prototype

[Suggestion] Add the version number in the build file

It would be good to have a comment in the build file with the version number, allowing to check whether an update is needed or no.
And it would be great if the website displays the latest version so that we can know about it.

Additionally, you might want to create tags for the 2.0.x releases in the repo, as you used to do for the 1.x versions.

Placeholders.js not working with Knockout.js on IE8?

It seems that the placeholders.js does not work when you have data-bindings from knockout attached to the input values. The placeholders will only show up after you click on the input values...

Here is the image of HTML and the knockout bindings, after a click. but you can see that the third input is empty.
image

Attached is code if needed to debug and determine the cause. I will be digging into this as well to understand a solution.
You will need to add the '<' to use the below code

div id="form">
input type="email" class="input-form" placeholder="Email Address" data-bind="value: email">
span data-bind="text: email">
input type="password" class="input-form" placeholder="Password" data-bind="value: password">
span data-bind="text: password">
input type="password" class="input-form" placeholder="Confirm Password" data-bind="value: confirmpassword">
input type="text" class="input-form" placeholder="testing">
/div>

script src="knockout-2.1.0.js"></script>
script src="placeholders.jquery.js"></script>
script>
function Info() {
this.email = ko.observable(),
this.password = ko.observable(),
this.confirmpassword = ko.observable();
}

var viewModel = new Info();
var elementBindingScope = document.getElementById('form');
ko.applyBindings(viewModel, elementBindingScope);

/script>

Flash of incorrect styling/unmasked password character when hide-on-input is on

When the polyfill runs in "hide-on-input" mode (rather than "hide-on-focus") there is a flash of placeholder-styled text when you type the first character into the input.

This is more of a problem with password inputs, since the flash renders the first password character in plain text, rather than masking it (since the mask won't be applied until keyup).

Currently, this is not a trivial fix, but I hope to get a patch in a future version.

Placeholders are not cleared when javascript calls form.submit() on Internet Explorer

In Internet Explorer, placeholder texts are not being cleared when javascript code calls form.submit() on a form that contains inputs with placeholders; this is because on Internet Explorer, in contrast to other browsers, the form.submit() method does not trigger an onsubmit event, so the Placeholders.js code responsible for clearing any placeholder texts, never gets called.
I've solved this locally by modifying the addEventListener(elem, event, fn) method in Placeholders.js as follows:

// Cross-browser DOM event binding
function addEventListener(elem, event, fn) {
    if (event == "submit") {
        setupTriggerEventBeforeSubmit(elem);
    }
    if (elem.addEventListener) {
        return elem.addEventListener(event, fn, false);
    }
    if (elem.attachEvent) {
        return elem.attachEvent("on" + event, fn);
    }
}

, and adding an extra method

function setupTriggerEventBeforeSubmit(form) {
    if (! form.submit.oldsubmit) {
        var oldsubmit = form.submit;
        form.submit = function() {
            if (form.dispatchEvent) {
                var newEvent = document.createEvent("HTMLEvents");
                newEvent.initEvent("submit", true, false);
                form.dispatchEvent(newEvent);
            } else if (form.fireEvent) {
                form.fireEvent("OnSubmit");
            }
            form.submit.oldsubmit.call(form);
        }
        form.submit.oldsubmit = oldsubmit;
    }
}

Incorrect classNameRegExp

Hello,

This is a small issue.

classNameRegExp = new RegExp("\\b" + placeholderClassName + "\\b")
elem.className = elem.className.replace(classNameRegExp, "");

doesn't work properly if the className is "custom-placeholdersjs placeholdersjs" because the resulting string will be "custom- placeholdersjs"

classNameRegExp = new RegExp("(?:^|\\s)" + placeholderClassName + "(?!\\S)")
seems to do the work (from http://stackoverflow.com/questions/195951/change-an-elements-css-class-with-javascript )

Script not working on dynamically inserted elements

Elements that are inserted through JavaScript don't get the placeholder functionality.
It works when elements are added with jQuery, however it doesn't work on elements added through AngularJS.

Also tried triggering it manually with Placeholders.enable(element); but it doesn't work.

No licence

Hello,

Please could you clarify what licence you're releasing this under? Default under most copyright law is for no permission to do anything to be implied, so a licence would be useful.

Cheers,

Tim

Set options through JavaScript.

I'd like to request the ability to configure the placeholder options through JavaScript, instead of through data- elements on the html tag.

IE8 cursor position

When editing string in 'input' type 'text' (in the middle of the string) cursor jumps to the end of the string.

How to get this to work on a Marketo form?

Hi! I am using placeholders for a Marketo form, which is loaded with a snippet of Javascript. Since that is a dynamic piece of content, how do I go about loading the placeholders script? Including it at the bottom of the body tag doesn't work. What happens is the placeholders briefly appear on page load, and then they disappear and the fields are blank. So I'm thinking something happens as the Marketo form loads that makes the placeholders disappear in IE7-8.

Failure on browsers supporting placeholder

I might be doing things wrong, so apologies if that's the case.

The issue I'm having is that calling Placeholder.enable() on a browser which supports placeholders produces a fatal error, since "inputs" is never initialised.

Maybe I should check before, but I was expecting this lib to be a kind of drop-in replacement: just import, and that's all.

My quick-fix is just override enablePlaceholders() and disablePlaceholders() with empty functions when not (test.placeholder === void 0)

Password placeholder in IE8

Hi I just implemented this on my landing page and it works like a charm. Except for one small thing:

My password placeholder is shown with only **********, because that is the default password input field behaviour.

Has anybody found a fix for that?

Improve the build system

Currently the built script consists of 2 concatenated files, main.js and utils.js. The contents of each file is wrapped in an IIFE, which is stupid. The entire script should be wrapped in one, rather than split into 2.

The Grunt script could be updated to add this wrapper.

hideOnFocus doesn't work in Chrome( v21)

I wanted to override the default behavior but the code below doesn't work. It's ok in Firefox (v 14) and IE as indicated in the doc

   Placeholders.init
      hideOnFocus: true

Class not removed in IE9, for disabled/hidden inputs

I have two cases where the class is not being removed in IE9.

A field that is disabled (then made editable via jquery), on focus the placeholderjs class is not removed, and in a case where I am using Placeholders.disable(); and then Placeholders.enable(); (due to an issue I am having with another plugin) the class is added twice and then one of them is removed on focus leaving the original class so the faded text is still "greyed".

The other case I notice this is after a input box starts as being display none and then is made visible caused by javascript on a select box change, (ie other). The input is made visible but focus on the input does not remove the placeholderjs class.

I tried creating a fiddle of the issue but don't seem to be able to load in the correct js without causing an issue with the js loading? (http://jsfiddle.net/dS2ds/3/)

IE8 dummy text equal to placeholder

When typing 'First name' into 'input' type 'text' with the placeholder value 'First name', the value of input is resetting to an empty string.

IE9 submitting placeholder text

In IE9 placeholder text is being submitted if no value has been entered into the input field.

This is not happening in IE8.

Would be great if you could look into this.

IE10 data-placeholder-focus ignored

On IE10, setting the data-placeholder-focus attribute to false does not result in the same behaviour as IE < 10 and Safari & Chrome. Instead the placeholder text still disappears when the input gets focus.

This is probably because IE10 purportedly supports placeholder, but losing the placeholder text on focus is part of its default behaviour.

password field issues w/ IE9

first of all - awesome plugin. i so want this to work :)

I'm using on a login-page (user|pass) with IE9. the password is type-input, when i fail login and bring them back to the page with value prepopulated in the input tag. eg:

it renders as a non-password input showing the value attribute, not the place holder. looks really bad as it shows the users password in the clear.

any ideas?

Feature request: Multiline placeholders in text area

I know that new lines are not supported as part of the HTML5 spec, but in some cases it's very useful to display a placeholder with multiple lines in a text area. Interestingly, when I tested this plugin on IE6 it behaved as I would like placeholders to behave (Multiline, don't submit placeholder data to server)

I tried to change this line:
Placeholders.nativeSupport = test.placeholder !== void 0;
to
Placeholders.nativeSupport = false;

to just force the placeholder js to execute on modern browsers (tested in FF 27) and it actually did show the placeholder as multiline, however, when I submitted my form, the placeholder text was submitted to the server even though it looked like it was being cleared out.

So anyway, my feature request is to have an option that could be turned on or off to detect multiline placeholders in textareas and apply the js polyfill to those even on modern browsers.

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.